Question bank › Binary Search
Dsa Binary Search Medium

Count Occurrences of Target in Sorted Array

Given a sorted array of integers and a target integer, write a function that returns the number of times the target occurs in the array. Input Format: - The first line contains an integer n, the length of the array. - The second line contains n integers, representing the sorted array. - The third line contains the target integer. Output Format: - Print the count of the target in the array. Example: Input: 9 1 2 2 2 3 3 4 5 6 2 Output: 3

Key concepts

binary_searcharrays

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