Geeksforgeeks

Error

Given two arrays **a **and **b**. Given **q** queries each having a positive integer **i** denoting an index of the array **a**. For each query, your task is to find all the elements less than or equal to **q _{i}** in the array

**Example 1:**

**Input:
**N=6
a[] = {1, 2, 3, 4, 7, 9}
b[] = {0, 1, 2, 1, 1, 4}
Query 1 -> 5
Query 2 -> 4
**Output :** 6
6
**Explanation**: For 1^{st} query, the given index is 5,
A[5] is 9 and in B all the elements
are smaller than 9.
For 2^{nd} query, the given index is 4,
A[4] is 7 and in B all the elements
are smaller than 7.

**Your Task:**

Since, this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function **find()** that takes** array a , array b, array q **as parameters** **and returns an array that contains the answer to the corresponding queries.

**Expected Time Complexity:** O(n).

**Expected Auxiliary Space:** O(n).

**Constraints:**

1 ≤ n ≤ 10^{7}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Count the elements

...