Find The Next

Given an array of integers A of size N. You are given another array of integers B of size Q representing queries.

For ith query, you need to find an integer Z strictly greater than B[i]
such that Z is not present in the array A. You need to minimize the value of Z.

Return an array of size Q denoting answer for each query.



Input Format

The first argument given is the integer array A.
The second argument given is the integer array B.

Output Format

Return an array of integers denoting answer for each query.

Constraints

1 <= N, Q <= 100000
1 <= A[i], B[i] <= 10^9 

For Example

Input 1:
    A = [1, 5, 10, 2, 7]
    B = [1, 6, 9, 12, 11]
Output 1:
    [3, 8, 11, 13, 12]

Input 2:
    A = [7, 14, 9, 6, 11, 12, 14]
    B = [18, 14, 2, 18, 16, 2, 10]
Output 2:
    [19, 15, 3, 19, 17, 3, 13] 
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Find The Next on Interview Code Editor
Sign Up
to access hints and editorial solutions for Find The Next

Discussion


Loading...
Click here to start solving coding interview questions