Skip to contentKEEP THE CRAFTTHE SANCTUARY

Minimum of a Rotated Sorted Array

Find the smallest value of a sorted array that has been rotated.

The problem

Implement Solution.findMin(nums). nums holds between 1 and 5,000 distinct integers. It was sorted in increasing order and then rotated zero or more times, so [1, 2, 3, 4, 5] might become [3, 4, 5, 1, 2] or stay as it is. Return the smallest value in nums. Your solution must run in O(log n) time.

Starter code

class Solution:
    def findMin(self, nums):
        pass

Public examples

  1. nums = [3, 4, 5, 1, 2]gives1
  2. nums = [-4]gives-4
  3. nums = [2, 3, 4, 5, 1]gives1

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.