Dsa
Binary Search
Easy
Target Range in Sorted Array
Given a sorted array of integers, write a function that returns the starting and ending position of a given target value. If the target is not found in the array, return [-1, -1]. Your solution should run in O(log n) time using binary search.
Input:
- A single line containing space-separated integers representing the sorted array.
- An integer as the target.
Output:
- A list containing the starting and ending positions of the target.
Example:
Input:
5 7 7 8 8 10
8
Output:
[3, 4]
Key concepts
binary_searcharrayrange
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