P18868 [GeeksforGeeks] Stack permutations
普及
题目描述

You are given two arrays A and B of unique elements of size N. Check if array B is a stack permutation of the array A or not.
Stack permutation means that array B can be created from array A using a stack and stack operations.

Example 1:
Input:
N = 3
A = {1,2,3}
B = {2,1,3}
Output:
1
Explanation:
1. push 1 from A to stack
2. push 2 from A to stack
3. pop 2 from stack to B
4. pop 1 from stack to B
5. push 3 from A to stack
6. pop 3 from stack to B

Example 2:
Input:
N = 3
A = {1,2,3}
B = {3,1,2}
Output:
0
Explanation:
Not Possible

Your Task:
You don't need to read input or print anything. Your task is to complete the function isStackPermutation() which takes two arrays A and B as inputs and returns 1 if it is a stack permutation otherwise returns 0.

Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)

Constraints:
1 <= N <= 10^{5}
0 <= A[i], B[i] <= 2*10^{5}
Sum of N over all test cases doesn't exceeds 10^{6}

输入格式

见题面

输出格式

见题面

样例输入
N = 3 A = {1,2,3} B = {2,1,3}
样例输出
1