Count of Smaller Elements
Practice this coding question on Coding Gurukul.
Problem statement
A freight desk accepts parcels whose recorded weight is at most a specified limit. Count how many entries in the current manifest qualify. Your task Given n integer values and a threshold x, count the values less than or equal to x. Important details The comparison is inclusive: a value exactly equal to x qualifies. Count entries rather than distinct values, so repeated qualifying measurements each contribute one. The array need not be sorted. Negative values and a negative threshold are permitted for general comparison practice. If no entries qualify, the answer is zero; if all qualify, it is n. A direct scan is enough. Worked example For threshold 4 and values 4, 1, 7, 4, 9, three entries qualify: the first 4, the 1, and the second 4.
Input format
The first line contains n x. The second line contains n integers.
Output format
Print the number of values <= x.
Constraints
1 <= n <= 100000; -1000000000 <= x, a[i] <= 1000000000.
Sample input
5 4 4 1 7 4 9
Sample output
3
Sign in to run or submit a solution in C++, Java or Python.