FastPrepMinimum in a Rotated Sorted Array

Minimum in a Rotated Sorted Array

NVIDIA logoNVIDIA● MediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

The array nums contains distinct integers. It was sorted in strictly increasing order and then rotated; a full-length rotation may leave it unchanged.

Return the minimum value in the array. Your final algorithm must use O(log n) time, where n = nums.length.

Function

findMin(nums: int[]) → int

Examples

Example 1

nums = [3,4,5,1,2]return = 1

The increasing lower segment begins at1.

Example 2

nums = [4,5,6,7,0,1,2]return = 0

A rotation places0 between7 and1.

Example 3

nums = [11,13,15,17]return = 11

A full-length rotation leaves the increasing array unchanged.

Constraints

  • 1 <= nums.length <= 5000.
  • -5000 <= nums[i] <= 5000.
  • All values are distinct, and nums is a rotation of a strictly increasing array.

More NVIDIA problems

See NVIDIA hiring insights
public int findMin(int[] nums) {
    return 0;
}
nums[3,4,5,1,2]
expected1
Checking account…