Number of elements

2

1 votes
, Binary search algorithm, Searching algorithm, Algorithms, Easy, Binary Search
Problem

You are given the following

  • An array \(A\) of size \(N\) 
  • An integer \(h\) 

Your task is to print the number of elements in \(A\) that are greater than \(h\). You are given a total of \(K\) such tasks. 

Example

Consider N = 5, A = [9, 3, 5, 1, 15], K = 2, and h = [2, 10].

  • For the 1st query, the elements greater than 2 are [9, 3, 5, 15]. Thus answer is 4.

  • For the 2nd query, the elements greater than 10 are [15]. Thus answer is 1.

Therefore the answer is [4, 1].

Function description

Complete the Solve function provided in the editor. This function takes the following 4 parameters and returns a list of values:

  • N: Represents the size of array A.
  • A: Represents the elements of the array.
  • K: Represents the size of array h.
  • h: Represents the element of the query array.

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

  • The first line conains \(N\) denoting the size of the array.
  • The next line contains \(N\) space-separated integers denoting the elements of array \(A\).
  • The next line  contains an integer \(K\) denoting the number of tasks.
  • Next \(K\) lines contains an integer \(h\).

Output format

For each task, print in a new line the number of elements in \(A\) that are greater than \(h\).

Constraints

\(1\le N \le 10^5 \\ 1\le A[i] \le 10^9\\ 1\le K \le 10^5 \\ 1\le h \le 10^9 \)

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the array \(A = [1, 5, 3, 2, 4]\), there are $$3$$ elements that are greater than $$2$$.

Editor Image

?