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)
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!
@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.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This problem can be found in Leetcode: leetcode.com/problems/valid-mounta...
My approach with test case:
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!
@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.