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

I assume, [0, 2, 5] and [5, 2, 1] both are valid mountain array. My approach with test case:

[0, 2, 5]

[5, 2, 1]

def is_mountain_array(nums): is_peak_found = False for i in range(1, len(nums)): if nums[i] == nums[i-1]: return False elif nums[i] < nums[i-1]: if not is_peak_found: is_peak_found = True elif nums[i] > nums[i-1]: if is_peak_found: return False return True if __name__ == "__main__": test_case = [0, 2, 3, 4, 5, 2, 1, 0] accepted_result = True result = is_mountain_array(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 = is_mountain_array(test_case) assert result == accepted_result, (test_case, accepted_result, result) test_case = [0, 1, 2, 3, 2, 1] accepted_result = True result = is_mountain_array(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 = is_mountain_array(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 = is_mountain_array(test_case) assert result == accepted_result, (test_case, accepted_result, result) test_case = [0, 2, 1] accepted_result = True result = is_mountain_array(test_case) assert result == accepted_result, (test_case, accepted_result, result) test_case = [0, 2, 3] accepted_result = True result = is_mountain_array(test_case) assert result == accepted_result, (test_case, accepted_result, result) test_case = [5, 2, 1] accepted_result = True result = is_mountain_array(test_case) assert result == accepted_result, (test_case, accepted_result, result)

I assume,

`[0, 2, 5]`

and`[5, 2, 1]`

both are valid mountain array.My approach with test case: