All problems
Valid Mountain Array
Problem
Return True if arr is a mountain array: strictly increasing to a peak and then strictly decreasing, with at least three elements.
Walk up while values increase, require that the peak is neither the first nor the last element, then walk down and require reaching the end. Equal neighbours invalidate the mountain.
Hint
The up-walk must stop before the last element and the down-walk must reach it.
Test cases
case 1
in: [[2,1]]
expected: false
case 2
in: [[3,5,5]]
expected: false
case 3
in: [[0,3,2,1]]
expected: true
case 4
in: [[0,1,2,3,4,5,6,7,8,9]]
expected: false
case 5
in: [[1,3,2]]
expected: true
case 6
in: [[9,8,7,6,5]]
expected: false
Starter codePython
def valid_mountain_array(arr):
# Your code here
pass6 test cases · run your code against them in the editor