Write a python function which returns True elements in a given list is monotonically increasing or decreasing, return False otherwise


Topic: Write a python function which returns True elements in a given list is monotonically increasing or decreasing, return False otherwise

Solution

def isMonotonic(A):  
    return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or
            all(A[i] >= A[i + 1] for i in range(len(A) - 1))) 
			
			



List all Python Programs