All problems
0692EasyArray

Is the Survey Line a Single Ridge

Tracked in this browser only
Write code

Trains the technique from

LeetCode 941Valid Mountain Array

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A survey walks a straight line and records the ground elevation at each station, giving heights in walking order.

The line is a single ridge when both of the following hold:

  • it has at least three stations;
  • there is a station p, neither the first nor the last, such that the elevations strictly increase from the first station up to p, and strictly decrease from p on to the last station.

Strictly means no two neighbouring stations on either side may record the same elevation. Return true when the line is a single ridge and false otherwise.

Examples

Example 1

Input
heights = [0, 3, 1]
Output
true

Station 1 is neither the first nor the last, the elevation rises from 0 to 3 before it, and falls from 3 to 1 after it.

Example 2

Input
heights = [4, 7, 9, 11]
Output
false

The elevations keep rising to the last station, so there is no station strictly inside the line with a fall after it.

Example 3

Input
heights = [1, 2, 2, 1]
Output
false

Stations 1 and 2 both record 2. That pair is neither a strict rise nor a strict fall, so no station splits the line into the two required parts.

Constraints

  • 1 <= heights.length <= 10^4
  • 0 <= heights[i] <= 10^4

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_single_ridge(heights: list[int]) -> bool:
Java
public boolean isSingleRidge(int[] heights)
September 7
Apply