Valid Mountain Array
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
1 <= len(arr) <= 500 <= arr[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Arrays problems
- Best Rotation ScoreMedium
- Best Stretch Around a RingMedium
- Fewest Swaps to SortMedium
- Insert IntervalMedium
- Longest HillMedium
- Maximum SubarrayMedium
- Next PermutationMedium
- Nudge Every ItemMedium