Target occurs multiple times
Input
nums = [2, 4, 4, 4, 6], target = 4
Output
[1, 3]
The target 4 first appears at index 1 and last at index 3.
Full lesson preview
Find the starting and ending positions of a target value in a sorted array using binary search.
Problem statement
Task
Examples
Input
nums = [2, 4, 4, 4, 6], target = 4
Output
[1, 3]
The target 4 first appears at index 1 and last at index 3.
Input format
Output format
Constraints
Samples
Input
search_range([1,2,3,3,3,4], 3)
Output
[2, 4]
3 appears from index 2 through 4.