Question bank › Binary Search
Dsa Binary Search Easy

First Occurrence of Target in Duplicates

Write a program to find the index of the first occurrence of a target value in a sorted array that may contain duplicates. If the target is not found, return -1. The input consists of a line of space-separated integers representing the array followed by the target integer on the next line. Output the index of the first occurrence of the target value. Example: Input: 1 2 2 2 3 4 5 2 Output: 1

Key concepts

binary_searchduplicates

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.