Ctrl K

First and Last Copy

Medium
A results table scores is sorted in non-decreasing order, and equal values may repeat. Find where the value wanted sits: return [first position, last position] (0-based). If the value is not there, return [-1, -1]. The list can be very long, so your solution must run in O(log n).
Example 1
scores=[2, 4, 4, 4, 9, 11], wanted=4 → [1, 3]

The 4s occupy positions 1 through 3.

Example 2
scores=[-3, 0, 6], wanted=5 → [-1, -1]

There is no 5 in the list.

Example 3
scores=[7], wanted=7 → [0, 0]
Constraints
  • 0 ≤ len(scores) ≤ 10⁵
  • -10⁹ ≤ scores[i], wanted ≤ 10⁹
  • scores is sorted in non-decreasing order
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFind in a Shifted Sorted Array MediumFind in a Row-Chained Grid MediumFind in a Shifted Array With Repeats MediumMinimum of a Shifted List MediumThe Lone Summit Medium
loading Python…
Input
scores=[2, 4, 4, 4, 9, 11], wanted=4
Expected
[1, 3]

Run checks the first 3 tests in your browser. Submit checks all 140 tests on the server, hidden ones included.