Design Gurus Logo
Blind 75
Find Minimum in Rotated Sorted Array (medium)

Problem Statement

You have an array of length n, which was initially sorted in ascending order. This array was then rotated x times. It is given that 1 <= x <= n. For example, if you rotate [1, 2, 3, 4] array 3 times, resultant array is [2, 3, 4, 1].

Your task is to find the minimum element from this array. Note that the array contains unique elements.

You must write an algorithm that runs in O(log n) time.

Example 1:

  • Input: [8, 1, 3, 4, 5]
  • Expected Output: 1
  • Justification: The smallest number in the array is 1.

Example 2:

  • Input: [4, 5, 7, 8, 0, 2, 3]
  • Expected Output: 0
  • Justification: The smallest number in the array is 0.

Example 3:

  • Input: [7, 9, 12, 3, 4, 5]
  • Expected Output: 3
  • Justification: In this rotated array, the smallest number present is 3.

Constraints:

  • n == nums.length
  • 1 <= n <= 5000
  • -5000 <= nums[i] <= 5000
  • All the integers of nums are unique.
  • nums is sorted and rotated between 1 and n times.

Try it yourself

Try solving this question here:

Python3
Python3