A sorted array of unique values was rotated an unknown number of times. Return its minimum element in O(log n) time.
Compare the middle with the right end. If nums[mid] > nums[hi], the drop (and the minimum) is right of mid; otherwise it is at mid or to its left.
1function findMin(nums: number[]): number {2let lo = 0, hi = nums.length - 1;3while (lo < hi) {4const mid = (lo + hi) >> 1;5if (nums[mid] > nums[hi]) lo = mid + 1;6else hi = mid;7}8return nums[lo];9}
Search the whole array.
Space: play/pause · ←/→: step