VOOZH about

URL: https://www.geeksforgeeks.org/dsa/maximum-element-in-a-sorted-and-rotated-array/

⇱ Maximum in a sorted and rotated array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Maximum in a sorted and rotated array

Last Updated : 19 Feb, 2026

Given a sorted array arr[] (may contain duplicates) of size n that is rotated at some unknown point, the task is to find the maximum element in it. 

Examples:

Input: arr[] = [5, 6, 1, 2, 3, 4]
Output: 6
Explanation: 6 is the maximum element present in the array.

Input: arr[] = [3, 2, 2, 2]
Output: 3
Explanation: 3 is the maximum element present in the array.

[Naive Approach] Linear Search - O(n) Time and O(1) Space

A simple solution is to use linear search to traverse the complete array and find a maximum. 


Output
6

[Expected Approach] Binary Search - O(log n) Time and O(1) Space

The array is sorted and then rotated, which means it consists of two individually sorted parts.
The maximum element lies just before the rotation point, i.e., at the end of the first sorted part.

Using Binary Search, we can efficiently locate this element by observing whether the current search range is already sorted. If it is sorted, the last element of that range is the maximum. Otherwise, we compare the middle element with the first element to decide which half contains the maximum and discard the other half.


Output
10
Comment
Article Tags:
Article Tags: