Minimum Length
Practice
2.5 (62 votes)
Arrays
1 D
Data structures
Problem
58% Success 15335 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 \)

 

 

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:20
65 votes
Tags:
ArraysC++1-DData StructuresGreedy AlgorithmsBasics of Greedy AlgorithmsMath
Points:20
27 votes
Tags:
ArraysData StructuresEasyHash MapsImplementationOne-dimensional
Points:30
Tags:
Medium