Loading practice problems…
Loading your practice workspace…
Loading code editor…
15 / 29
Sign in
Algorithms/Binary Search

Search in Rotated Sorted Array

medium30 min

A strictly increasing array was rotated at an unknown position. Given the rotated array and a target, return the target's index.

Return -1 when the target is absent, using logarithmic time.

Example 1

Inputnums = [4, 5, 6, 7, 0, 1, 2], target = 0

Output4

Example 2

Inputnums = [4, 5, 6, 7, 0, 1, 2], target = 3

Output-1

Constraints

  • 1 ≤ nums.length ≤ 5,000
  • All values are distinct.
Binary SearchArrays