116. Find First and Last Position of Element in Sorted Array

In a sorted array, find the starting and ending index of target. If not found, return [-1, -1].
Example 1
Input: nums = [5,7,7,8,8,10], target = 8
Output: [3,4]
Explanation: 8 appears from index 3 to 4.
Example 2
Input: nums = [5,7,7,8,8,10], target = 6
Output: [-1,-1]
Explanation: 6 is not in the array.
arraysbinary searchmedium
JavaScript
Loading...
Line 1, Char 1