Show problems as
Classic problem #852MediumArrayBinary SearchTernary Search

Peak Index in a Mountain Array

Real-world version: Kiln Ramp Peak
Tracked in this browser only
Read Peak Index in a Mountain Array on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Learn the pattern firstBasic Binary Search · Binary Search, animated step by step

A pottery kiln writes down its chamber temperature once a minute for one firing cycle. The log is a single ramp: reading by reading the temperature climbs to one hottest minute, and from that minute onward it drops, reading by reading, until the cycle ends. No two neighbouring readings are ever equal, the climb is at least one minute long, and so is the drop, so the hottest minute is never the first or last entry.

You are given the log as readings. Return the position of the hottest reading, counting positions from 0.

Your routine must run in time logarithmic in the length of readings.

Examples

Example 1

Input
readings = [120, 480, 910, 300]
Output
2

Position 2 holds 910. The readings before it climb, 120 then 480, and the reading after it, 300, is lower.

Example 2

Input
readings = [15, 62, 41, 33, 9]
Output
1

Position 1 holds 62, above the 15 that precedes it, and every later reading is below the one before it.

Example 3

Input
readings = [0, 4, 7, 12, 300, 299]
Output
4

The climb runs through positions 0 to 4 and the only drop is the final 299, so the hottest minute sits at position 4.

Constraints

  • 3 <= readings.length <= 10^5
  • 0 <= readings[i] <= 10^6
  • readings climbs strictly to one hottest entry and then drops strictly
  • the hottest entry is neither the first nor the last entry

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def kiln_ramp_peak(readings: list[int]) -> int:
Java
public int kilnRampPeak(int[] readings)