Skip to content
RED SAGSkills
easy15 ptsarrays

Single-Peak Elevation Profile

A hiking trail's elevation samples are given in heights. The trail is a *single-peak* trail when it has at least one strictly rising step, then at least one strictly falling step, and nothing else: it rises strictly to one peak and then falls strictly. Flat steps are not allowed.

Return true if the profile is a single-peak trail.

Example 1

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

Example 2

Input: heights = [3, 5, 5]
Output: false

Constraints

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

Climb while the next sample is higher, then descend while it is lower.

Hint 2

The peak cannot be the first or the last sample.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer, Game Developer

Run checks your code on 2 sample tests. Submit runs all 9 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.