heights. Every night, wind and rain reshape it, and all changes are computed at once from the previous day's profile:
- a point strictly higher than both of its neighbors (a peak) wears down by 1;
- a point strictly lower than both of its neighbors (a dip) fills up by 1;
- the two ends, the first and the last point, never change.
Sooner or later a day comes when the profile stops changing. Return that final profile.heights=[5, 1, 4, 2, 2] → [5, 3, 2, 2, 2]
Day 1: the dip 1 rises to 2, the peak 4 sinks to 3 → [5, 2, 3, 2, 2]. Day 2: 2 → 3 and 3 → 2 → [5, 3, 2, 2, 2]. Day 3: nothing changes, since no point is above or below both neighbors.
heights=[3, 7, 7, 3] → [3, 7, 7, 3]
Each 7 is higher than one neighbor but equal to the other, never strictly above both, so the ridge is already stable.
heights ≤ 100heights[i] ≤ 100heights=[5, 1, 4, 2, 2]
[5, 3, 2, 2, 2]
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.