โ† Amazon questions

Find index of largest number in a rotated sorted array

Filed under Amazon

Free read 1 of 3

Confirm if duplicate elements exist, as duplicates complicate finding the rotation pivot uniquely.

The question

Given a rotated sorted array of distinct integers, find the index of the largest element using a modified binary search approach.

Constraints

  • Array elements are distinct.
  • Time complexity must be O(log N).
  • Array is sorted in ascending order and rotated K times.

Examples

Input
nums = [4, 5, 6, 7, 0, 1, 2]
Output
3
Why
The largest element is 7, located at index 3.

Approach

  1. Confirm if duplicate elements exist, as duplicates complicate finding the rotation pivot uniquely.

Tips

  • What they are testing: Test arrays rotated 0 times, arrays rotated N-1 times, and minimal length arrays.
  • Common mistake: Confusing standard binary search conditions or failing to handle edge cases where the array is not actually rotated.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.