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