Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Peak Element In Rotated Array

Easy Acceptance 88% Points 20

Given a rotated sorted array of distinct integers, return the peak element in the array. The peak element is the maximum element in the rotated sorted array. The array was originally sorted in ascending order and then rotated at some unknown pivot. The peak element is the point where the rotation occurs and is greater than its neighboring elements.

Examples
Example 1

Example 1

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

Output: 7

Explanation: The maximum element is 7, which is greater than its neighbors and represents the peak of the rotated array.

Example 2

Example 2

Input: nums = [3,4,5,1,2]

Output: 5

Explanation: The element 5 is the largest element and is the peak where the rotation happens.

Example 3

Example 3

Input: nums = [1,2,3,4,5]

Output: 5

Explanation: The array is not rotated. The last element 5 is the maximum and therefore the peak element.

Constraints
  • 1 = nums.length = 105
  • -104 = nums[i] = 104
  • All values in nums are distinct
Topics
Recursion
Companies
Samsung
Added 19 Jul 2026 88% acceptance
Ln 1, Col 1Sign in to save your code
3 4 5 1 2
2