Question bank › Binary Search
Dsa Binary Search Warm-up

Count Occurrences of Target

You are given a sorted array of integers and a target integer. Write a function to count how many times the target appears in the array. If the target does not exist, return 0. Input Format: The first line contains an integer n, the size of the array. The second line contains n integers, the elements of the sorted array. The third line contains the target integer. Output Format: Print the count of occurrences of the target integer. Example: Input: 6 1 2 2 3 4 4 2 Output: 2

Key concepts

binary_searcharrayscounting

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
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.