## DEV Community is a community of 758,529 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Discussion on: Day-9 Valid Mountain Array

Ahmedur Rahman Shovon • Edited on

This problem can be found in Leetcode: leetcode.com/problems/valid-mounta...

My approach with test case:

``````class Solution:
def validMountainArray(self, arr: List[int]) -> bool:
peak_found = False
for i in range(1, len(arr)):
if arr[i] == arr[i-1]:
return False
if arr[i] < arr[i-1]:
if peak_found == False:
if i == 1:
return False
else:
peak_found = True
else:
if peak_found == True:
return False
return peak_found

if __name__ == "__main__":

solution = Solution()

test_case = [0, 2, 3, 4, 5, 2, 1, 0]
accepted_result = True
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 2, 3, 3, 5, 2, 1, 0]
accepted_result = False
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 1, 2, 3, 2, 1]
accepted_result = True
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 2, 3, 4, 5, 2, 1, 5, 4, 1]
accepted_result = False
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 2, 3, 4, 5, 2, 1, 3, 2, 1]
accepted_result = False
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 2, 1]
accepted_result = True
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [0, 2, 3]
accepted_result = False
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

test_case = [5, 2, 1]
accepted_result = False
result = solution.validMountainArray(test_case)
assert result == accepted_result, (test_case, accepted_result, result)

``````
Gabriel

Aren't the last two test cases wrong? The expected answer on leetcode returns false and not true. I am trying to solve this now!

Ahmedur Rahman Shovon

@gabriel , yes you are right. I did not notice about the leetcode problem. I have updated the old answer.

Thank you for finding the bug.

• Shovon