Hard

Quiz

#154 Find Minimum in Rotated Sorted Array II

APPROACH

A sorted array of length n (which may contain duplicates) has been rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:

- [4,5,6,7,0,1,4] after 4 rotations.

- [0,1,4,4,5,6,7] after 7 rotations.

Rotating [a[0], a[1], a[2], ..., a[n-1]] once gives [a[n-1], a[0], a[1], a[2], ..., a[n-2]].

Given the rotated array nums that may contain duplicates, return its minimum element. Minimize the total number of operations.

Example 1:

Input: nums = [1,3,5]
Output: 1

Example 2:

Input: nums = [2,2,2,0,1]
Output: 0
1 of 4
1:00

What is the optimal approach for this problem?