Blind 75
17 / 75Free practice

Find Minimum in Rotated Sorted Array

Medium · Binary search

Jump to code

A nonempty array of distinct integers was sorted ascending, then rotated zero or more positions. Find its minimum in logarithmic time.

Examples

Example 1

nums = [3,4,5,1,2]

Output: 1

Example 2

nums = [4,5,6,7,0,1,2]

Output: 0

Constraints

  • 1 <= nums.length <= 1000
  • -1000 <= nums[i] <= 1000
Need a hint?

Compare the middle element with the rightmost element.

Asked in real interviews

Candidates reported versions of Find Minimum in Rotated Sorted Array from these company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 8 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  [
    3,
    4,
    5,
    1,
    2
  ]
]
Expected
1
Case 2
Input
[
  [
    4,
    5,
    6,
    7,
    0,
    1,
    2
  ]
]
Expected
0
Case 3
Input
[
  [
    11,
    13,
    15,
    17
  ]
]
Expected
11
Case 4
Input
[
  [
    2,
    3,
    4,
    5,
    1
  ]
]
Expected
1
Case 5
Input
[
  [
    1
  ]
]
Expected
1

Drafts are saved per language in this browser when storage is available.