<jupyter_start><jupyter_text>Monotonic Array[link](https://www.algoexpert.io/questions/Monotonic%20Array)  My Solution<jupyter_code>def isMonotonic(array):
    # Write your code here.
    if len(array) <= 1:
		return True
	notDecrease = None
	for i in range(len(array) - 1):
		if notDecrease == None:
			if array[i] == array[i+1]:
				continue
			else:
				notDecrease = True if array[i+1] > array[i] else False
		else:
			if array[i] == array[i+1]:
				continue
			if not ((array[i] < array[i+1]) ^ notDecrease):
				continue
			else:
				return False
	return True
def isMonotonic(array):
    # Write your code here.
    up = True # not-decreasing
    down = True # not-increasing
    for i in range(len(array) - 1):
        if array[i] < array[i+1]:
            down = False
        elif array[i] > array[i+1]:
            up = False
        else:
            continue
        
        if up is False and down is False:
            return False
    return True<jupyter_output><empty_output><jupyter_text>Expert Solution<jupyter_code>def isMonotonic(array):
    if len(array) <= 2:
        return True
    
    direction = array[1] - array[0]
    for i in range(2, len(array)):
        if direction == 0:
            direction = array[i] - array[i - 1]
            continue
        if breakDirection(direction, array[i - 1], array[i]):
            return False
        
    return True

def breakDirection(direction, previousInt, currentInt):
    difference = currentInt - previousInt
    if direction > 0:
        return difference < 0
    return direction > 0
def isMonotonic(array):
    isNonDecreasing = True
    isNonIncreasing = True
    for i in range(1, len(array)):
        if array[i] < array[i - 1]:
            isNonDecreasing = False
        if array[i] > array[i - 1]:
            isNonIncreasing = False
            
    return isNonDecreasing or isNonIncreasing<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10534591194968554, 'fraction_numerical': 0.012578616352201259, 'mean_word_length': 2.3432574430823117, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '583698', 'license': 'MIT', 'n_tokens_mistral': 668, 'n_tokens_neox': 618, 'n_words': 168, 'path': 'algoExpert/monotonic_array/solution.ipynb', 'repo_name': 'maple1eaf/learning_algorithm', 'size': '1908'}