Skip to content

Instantly share code, notes, and snippets.

@zedbeit
Created July 19, 2022 09:59
Show Gist options
  • Save zedbeit/32cfc2be6cfe672c8009ed962c692de9 to your computer and use it in GitHub Desktop.
Save zedbeit/32cfc2be6cfe672c8009ed962c692de9 to your computer and use it in GitHub Desktop.
Monotonic Array
Write a function that takes in an array of integers and returns a boolean representing whether the array is monotonic.
An array is said to be monotonic if its elements, left to right , are entirely non-increasing or entirely non-decreasing.
Non-increasing elements aren't neccessarily exclusively decreasing; they simply don't increase. Similarly, non-decreasing elements aren't exclusively increasing; they simply don't decrease.
Note that empty arrays and arrays of one element are monotonic.
Input:
array = [-3,-5,-15,-500,-500,-700,-703,-1001]
Ouput: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment