Dsa
Binary Search
Easy
Count Leftmost Occurrence
Given a sorted list of integers that may contain duplicates, and a target integer, return the count of occurrences of that target in the list. The input will specify a number of elements followed by the sorted elements and the target integer.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000).
- The second line contains n integers sorted in ascending order.
- The third line contains the target integer to count.
Output format:
- Print the count of occurrences of the target integer.
Example:
Input:
8
1 1 2 2 3 3 3 4
2
Output:
2
Key concepts
binary_searchcountingarray
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