Algorithm · ByteDance · Medium
You are given an integer array nums arranged in non-decreasing order and an integer target. Find the first and last positions where target occurs in nums. Return a two-element array [left, right] such that left is the smallest index with nums[left] == target and right is the largest index with nums[right] == target. If target is not present, return [-1, -1]. The algorithm must run in $$O(\log n)$$ time, where $$n$$ is the number of elements in nums. Example 1: Explanation:…
Checking your access…