Reference: LeetCode
Difficulty: Hard

## Problem

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

Find the minimum element.

You may assume duplicate exists in the array.

Example:

Follow-up Questions:

• Would allow duplicates affect the run-time complexity? How and why?

## Analysis

Sorting & Brute-Force as in 153.

### Divide & Conquer

Reference: Huahua

In the mid3 case, the result could be calculated in $O(1)$.

Note: Duplicates affect the run-time complexity. Consider the following case:

Time: $O(\log{N})$

• False: $T(N) = 2T(N/2) = O(N)$ ❌
• At each level, at least one side could be done in $O(1)$.
• True: $T(N) = O(1) + T(N/2) = O(\log{N})$

Space: $O(\log{N})$

The basic idea is that if nums[mid] >= nums[lo] we assure that the inflection point is on the right part.

However, unlike the solution in 153, we need 3 cases:

Recursion:

Iteration:

Invalid!

Time: $O(\log{N})$

• In the worst case scenario it would become $O(N)$.

Space: $O(\log{N})$

Comment
Junhao Wang
Hi, I was a master student at USC studying Computer Science.