Question bank › Binary Search
Dsa Binary Search Warm-up

Count Number of Ones

Given a sorted binary array (containing only 0s and 1s), find the count of 1s in the array. Input Format: - The first line contains an integer n, the number of elements in the array. - The second line contains n space-separated integers (0 or 1). Output Format: - Print the count of 1s in the array. Example: Input: 5 0 0 1 1 1 Output: 3

Key concepts

binary_searcharrayssearch

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.