You are given two arrays \(A\) and \(B\), of length \(N\). You can select any subarray and then sort the elements in ascending order of that subarray for arrays \(A\) and \(B\).
Find the minimum length of the subarray you can choose to make \(A\) and \(B\) same after performing the operation. \(A\) and \(B\) are permutations of each other.
Input Format:
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains an integer \(N\).
- The next line of each test case contains \(N\) space-separated integers, elements of array \(A\).
- The next line of each test case contains \(N\) space-separated integers, elements of array \(B\).
Output Format:
For each test case, print the minimum length of the subarray you can choose to make \(A\) and \(B\) same after performing the operation.
Constraints:
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^5 \\ 1 \leq A[i], B[i] \leq 10^5 \)
First test case:
We can choose a subarray from index \(2\) to \(3\) (1-based indexing). Hence, the answer is \(2\).
Second test case:
We can choose a subarray from index \(1\) to \(3\) (1-based indexing). Hence, the answer is \(3\).
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
Login to unlock the editorial
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