Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array nums (all unique elements), find and return the minimum element in O(log n) time.
lo=0, hi=n-1. The minimum is somewhere in [lo..hi].mid = lo + (hi-lo)/2.nums[mid] > nums[hi]: drop is in right half → lo = mid+1.hi = mid.lo == hi: nums[lo] is the minimum.A rotated sorted array has exactly one inflection point — the rotation pivot — where values drop. Comparing nums[mid] to nums[hi] tells us which half contains the drop:
nums[mid] > nums[hi]: the left half is "normally sorted" but the big values are there. The drop must be to the right.
nums[mid] ≤ nums[hi]: the right half is sorted (or equal). The minimum is at mid or further left.
We never compare to nums[lo] because the pivot could be exactly at mid.