The Old Monk
Practice
4 (200 votes)
Approved
Binary search
Easy
Open
Sorting
Problem
92% Success 21331 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Big Chandan is a dire lover of Biryani, especially Old Monk's Biryani. Today, he went over to have some of it. To his surprise, the waiter turns out be to be a coding geek and refuses to serves him unless Chandu solves his two- arrays problem, stated as:

Given two non-increasing array of integers A,B i.e A[i] >= A[i+1] and B[i] >= B[i+1] and for all i, 0 ≤ i < n-1.

The monkiness of two numbers is given by: M (A[i],B[j]) = j - i , if j >=i and B[j] >= A[i], or 0 otherwise.


Find the monkiness of the two arrays, that is given by: M (A,B)= max (M(A[i],B[j])) for 0≤ i, j< n-1.

Input Format:
The first line contains an integer, tc, denoting the number of test cases. The next line contains an integer, n, denoting the size of the two arrays. The size of both the arrays will be equal. After that line, the next line contains n integers denoting the numbers in the array A, and in the next line, there will be n numbers denoting the numbers in the array B.

Output format:
Print the monkiness of the two arrays.

Constraints:
1 <= Test Cases <= 50
1 <= N <= 105
1 <= Ai, Bi <= 1012

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
272 votes
Tags:
Binary SearchEasyOpenSorting
Points:20
38 votes
Tags:
ApprovedBinary SearchData StructuresEasyHash MapsHashing AlgorithmOpenSorting
Points:20
86 votes
Tags:
ApprovedBinary SearchEasyOpenSorting