The problem. Given an array of integers nums sorted in non-decreasing order (duplicates allowed), find the starting and ending position of a given target. If it isn't there, return [-1, -1]. Your algorithm must run in O(log n) time.
nums = [5, 7, 7, 8, 8, 10], target = 8 -> [3, 4]
nums = [5, 7, 7, 8, 8, 10], target = 6 -> [-1, -1]
nums = [], target = 0 -> [-1, -1]Members only · free account
The rest of this lesson, with 6 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson