Split Permutation
Practice
4 (3 votes)
Bit manipulation
Greedy algorithm
Basic programming
Bitmask
Basics of bit manipulation
Problem
85% Success 671 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of distinct integers and another array \(B\) which is a permutation of array \(A\). Find the maximum number of segments array \(A\) could be split such that within each segment, Array \(B\) is a permutation of array \(A\).

 INPUT FORMAT

The first line contains an integer, \(t\) - denoting the number of test cases.

The first line of each test case contains two integers \(n\) - denoting the length of the array \(A\).

The second line of each test case contains \(n\) integers — elements of array \(A\).

The second line of each test case contains \(n\) integers — elements of array \(B\) which is a permutation of array \(A\).

OUTPUT FORMAT

For each test case, print the answer in a new line.

 Constraints

\(1<=t<=1000\)

\(1<=n<=10^6\), sum of \(n\) across all test cases <= \(10^6\)

\(-10^{9} ≤ A_i ,B_i≤ 10^{9}\)

Array \(B\) is a permutation of array \(A\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
29 votes
Tags:
Ad-HocAlgorithmsApprovedMediumOpenTwo pointer
Points:30
17 votes
Tags:
ApprovedBasic ProgrammingBit manipulationMathMedium
Points:30
15 votes
Tags:
AlgorithmsApprovedBit manipulationMediumOpen