Find the Peaks
Real-world version: Ridge Points Along the ProfileThe statement here is our own: the same inputs, outputs and technique.
A survey profile is given as mountain, where mountain[i] is the height at station i.
A station is a ridge point when it is strictly higher than the station on each side of it. The first and last stations are never ridge points, since each has only one neighbour.
Return the ridge point stations in increasing order.
Examples
Example 1
- Input
- mountain = [2, 5, 3, 6, 4]
- Output
- [1, 3]
Station 1 stands at 5 above the 2 and the 3 beside it, and station 3 stands at 6 above the 3 and the 4 beside it.
Example 2
- Input
- mountain = [1, 3, 3, 1]
- Output
- []
Stations 1 and 2 are both at height 3, so neither stands strictly above both of its neighbours.
Example 3
- Input
- mountain = [1, 2, 3]
- Output
- []
The only station with a neighbour on each side is station 1, and it stands below station 2.
Constraints
- 3 <= mountain.length <= 100
- 1 <= mountain[i] <= 100
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 ridge_points(mountain: list[int]) -> list[int]:public List<Integer> ridgePoints(int[] mountain)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 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
More on the same topics
- Finding 3-Digit Even NumbersReal-world version: Three-Digit Even Numbers From the TilesEasy
- Divide an Array Into Subarrays With Minimum Cost IReal-world version: Cutting the Conveyor Into Three StretchesEasy
- Count PrimesReal-world version: Indivisible Catalogue NumbersMedium
- Equal Sum Grid Partition IReal-world version: Splitting the Yield Plot in TwoMedium