BugForge
DSA

Find a Version in a Rotated Release List

Mediumbinary search 00:00

A sorted list of distinct version numbers was rotated at an unknown pivot (e.g. [4,5,6,7,0,1,2]). Return the index of target, or -1. Must be O(log n).

Signature

searchRotated(nums: int[], target: int) → int
Example 1
nums = [4,5,6,7,0,1,2]
target = 0
output = 4
index 4
Example 2
nums = [4,5,6,7,0,1,2]
target = 3
output = -1
absent

Constraints

  • 1 ≤ n ≤ 5000
  • values distinct
Run checks the examples. Submit runs every hidden test (16, including large inputs that catch slow solutions).