Dsa
Binary Search
Medium
Count of Number in a Range
Given a sorted array of integers and a range [start, end], count how many numbers in the array fall within that range (inclusive). You should use binary search to find the boundaries of the range.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^5), the number of elements in the array.
- The second line contains n space-separated integers (the sorted elements).
- The third line contains two integers start and end (0 ≤ start ≤ end ≤ 10^9).
Output format:
- Print a single integer, the count of numbers in the range.
Example:
Input:
6
1 2 3 4 5 6
2 4
Output:
3
Key concepts
binary_searcharraycount
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now