Locate a Guaranteed Mountain Peak Logarithmically

Quick Overview

Locate a Guaranteed Mountain Peak Logarithmically. arr is guaranteed to rise strictly to one interior peak and then fall strictly.

Locate a Guaranteed Mountain Peak Logarithmically

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem arr is guaranteed to rise strictly to one interior peak and then fall strictly. Return the peak's zero-based index using O(log n) time. ```cpp class Solution { public: int peakIndexInMountainArray(vector<int>& arr); }; ``` ### Examples **Example 1:** ```text arr = [1,4,7,3] Output: 2 Explanation: The increasing side ends at7. ``` **Example 2:** ```text arr = [2,9,8,5,0] Output: 1 Explanation: Every entry after9 lies on the descending side. ``` ### Constraints - Array length lies in [3,100000]. - Entries are in [0,1000000]. - A strict mountain with an interior peak is guaranteed. ### Contract considerations Keep the required logarithmic search. ```hint Read the boundary condition What does the local slope reveal about the peak's side? ``` ### Boundary reminders Keep the required logarithmic search.

Overview: Locate a Guaranteed Mountain Peak Logarithmically. arr is guaranteed to rise strictly to one interior peak and then fall strictly.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

arr is guaranteed to rise strictly to one interior peak and then fall strictly. Return the peak's zero-based index using O(log n) time.

class Solution {
public:
    int peakIndexInMountainArray(vector<int>& arr);
};

Examples

Example 1:

arr = [1,4,7,3]
Output: 2
Explanation: The increasing side ends at7.

Example 2:

arr = [2,9,8,5,0]
Output: 1
Explanation: Every entry after9 lies on the descending side.

Constraints

  • Array length lies in [3,100000].
  • Entries are in [0,1000000].
  • A strict mountain with an interior peak is guaranteed.

Contract considerations

Keep the required logarithmic search.

Boundary reminders

Keep the required logarithmic search.