Dsa
Binary Search
Medium
Mountain Array Peak
You are given a mountain array, which is defined as an array that has a peak element which is greater than its neighbors. Write a function that finds the peak element using binary search. The peak element is defined as an element that is greater than or equal to its neighbors. If the array is [1, 3, 5, 4, 2], the peak is 5. Input is given as an integer array of size n. Output the peak element. Example:
Input:
5
1 3 5 4 2
Output:
5
Key concepts
binary_searcharraysearch
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now