FastPrepMaximum in a Rotated Sorted Array

Maximum in a Rotated Sorted Array

Amazon logoAmazon● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

A strictly increasing array of distinct integers was rotated at an unknown pivot. Return its maximum value in logarithmic time.

Function

findMaximumInRotatedArray(nums: int[]) → int

Examples

Example 1

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

The rotation pivot follows the maximum value six.

Example 2

nums = [10,20,30,40]return = 40

An unrotated array has its maximum at the final index.

Constraints

  • 1 <= nums.length <= 200000
  • nums contains distinct signed 32-bit integers
  • nums is an ascending array rotated zero or more positions

More Amazon problems

See Amazon hiring insights
public int findMaximumInRotatedArray(int[] nums) {
    // Write your code here.
}
nums[4,5,6,1,2,3]
expected6
Checking account…