A sorted array of unique integers was rotated at an unknown pivot. For example, [10, 20, 30, 40, 50]
becomes [30, 40, 50, 10, 20]
. Find the minimum element in this array.
This is yet another instance where we can simplify this problem to a One-sided Binary Search.
- Initially, it looks like we can’t do binary search because the array is not sorted
- However, we can notice that the array is in 2 sections:
- Numbers larger than the last element
(30, 40, 50)
- Numbers less than or equal to the last element
(10, 20)
- Numbers larger than the last element
- Thus, we can turn this into one-sided binary search by using a
feasible
function that compares against the last element of the array,<= nums[-1]
.