Medium · Binary Search
Find First and Last Position of Element in Sorted Array
Given an array nums sorted in non-decreasing order and a target, return [first, last], the first and last index at which target appears, or [−1, −1] if it does not appear.
Examples
Example 1
[5,7,7,8,8,10], t=8Output: [3, 4]
Example 2
[5,7,7,8,8,10], t=6Output: [-1, -1]
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.