Find index of largest number in a rotated sorted array
Filed under Amazon
Free read 1 of 3Confirm 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
Confirm if duplicate elements exist, as duplicates complicate finding the rotation pivot uniquely.
Iterate through the entire array to find the maximum element in O(N) time.
Use binary search. Compare mid element with the rightmost element to determine which half is sorted, narrowing down to find the inflection point (largest element).
Single element array, already sorted array without rotation.
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.