dsa · medium
First and Last Position in Sorted Array
nums is sorted non-decreasing. Return the inclusive start and end indices of the run of target. If target is absent, return [-1,-1].
Arguments
nums— sorted non-decreasing arraytarget— value whose run you locate
Example
nums = [5,7,7,8,8,10], target = 8 → [3,4].
target = 6 → [-1,-1].
Constraints
0 <= nums.length <= 10^5 nums is non-decreasing Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [5,7,7,8,8,10] 8 Expected: [3,4]
Example 2
Input: [5,7,7,8,8,10] 6 Expected: [-1,-1]
Example 3
Input: [] 0 Expected: [-1,-1]