Sign in $ create-account
~/problems ~/discussion ~/contests ~/submission
← ~/problems
P2004

Count Not Greater

Medium
// Description
Given a sorted array and a value x, output how many elements are less than or equal to x.
// Input
The first line contains an integer n (1 <= n <= 10^5). The second line contains n integers in non-decreasing order. The third line contains the query value x.
// Output
A single integer: the count of elements <= x.
// Hint
A binary search (upper bound) answers each query in O(log n).
// Samples
Sample Input
5
1 3 3 5 8
4
Sample Output
3
// Problem Info
DifficultyMedium
Acceptance70%
Time Limit1000 ms
Memory Limit65536 KB
Accepted7
Binary SearchSortings
// Discussion

No Discussion