435. Find the Pivot in Rotated Sorted Array

EasyBinary SearchArrayBinary Search

Given a rotated sorted array of distinct integers nums, find the index of the pivot — the index of the largest element (where the rotation break occurs). If the array is not rotated, return the last index.

Input: A rotated sorted array of distinct integers.

Output: Index of the largest element (pivot).

Examples

Example 1
Input: [4,5,6,7,0,1,2]
Output: 3
Explanation: The largest element is 7 at index 3. Rotation point is between index 3 and 4.
Example 2
Input: [3,4,5,1,2]
Output: 2
Explanation: Largest is 5 at index 2.
Example 3
Input: [1,2,3,4,5]
Output: 4
Explanation: Not rotated; largest is at last index 4.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →