Minimum in a Rotated Sorted Array
Problem statement
Given a nonempty array nums formed by rotating a strictly increasing integer array, return its minimum element.
Rotating moves a prefix to the end while preserving the order within each part. Zero rotations are allowed. All elements are distinct.
Your solution must use O(log n) time and O(1) extra space.
Function
minimumRotatedArray(nums: int[]) → intExamples
Example 1
nums = [3,4,5,1,2]return = 1The increasing sequence [1, 2, 3, 4, 5] was rotated, and its minimum remains 1.
Example 2
nums = [1,2,3]return = 1A zero rotation is valid; the first value is the minimum.
Example 3
nums = [5]return = 5A singleton has no different minimum.
Constraints
1 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9- All values are distinct, and nums is a rotation of a strictly increasing array.