Question bank › Binary Search
Dsa Binary Search Medium

Find First and Last Position

Given a sorted array of integers that may contain duplicates, and a target integer, return the first and last position (0-based index) of the target in the array. If the target is not found, return [-1, -1]. Input format: - The first line contains space-separated integers representing the sorted array. - The second line contains a single integer representing the target. Output format: - A list of two integers representing the first and last position of the target. Example: Input: 1 2 2 2 3 4 5 2 Output: 1 3

Key concepts

binary_searcharray

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.