FunctionRacerProblemsRace

Valid Mountain Array

EasyArraysPython, JavaScript, TypeScript, Java, C++

A list is a mountain if it has at least 3 items and there is a peak position p, not the first or last, such that the items strictly increase up to p and then strictly decrease after it.

Return True if arr is a mountain, otherwise False.

Example 1

arr [1,3,5,4,2]
returns true

Up to 5, then down.

Example 2

arr [1,2,2,1]
returns false

The repeated 2 is a flat step, so it is not a mountain.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems