First and Last Position
nums is sorted in non-decreasing order and may hold repeats. Return [first, last], the first and last index at which target appears, or [-1, -1] if it never does.
Example 1
nums [5,7,7,8,8,10]
target 8
returns [3,4]
8 is at indices 3 and 4.
Example 2
nums [5,7,7,8,8,10]
target 6
returns [-1,-1]
No 6.
Constraints
0 <= len(nums) <= 40-20 <= nums[i], target <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.