Minimum Length
Practice
2.5 (62 votes)
Arrays
1 D
Data structures
Problem
59% Success 15440 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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 \)
Submissions
Please login to view your submissions
Similar Problems
Points:20
26 votes
Tags:
EasyOne-dimensionalString Manipulation
Points:20
138 votes
Tags:
ArraysData StructuresEasyOne-dimensional
Points:20
77 votes
Tags:
ArraysBasic ProgrammingData StructuresEasyOne-dimensional
Editorial