Peak Index in a Mountain Array
Real-world version: Kiln Ramp PeakThe statement here is our own: the same inputs, outputs and technique.
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.
def kiln_ramp_peak(readings: list[int]) -> int:public int kilnRampPeak(int[] readings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's