Skip to content

Instantly share code, notes, and snippets.

@Jonniie
Created January 14, 2026 20:41
Show Gist options
  • Select an option

  • Save Jonniie/1ebe7ff044e6e50f45255398fcdb55f5 to your computer and use it in GitHub Desktop.

Select an option

Save Jonniie/1ebe7ff044e6e50f45255398fcdb55f5 to your computer and use it in GitHub Desktop.
896. Monotonic Array

Leetcode #896

Approach

My approach was to figure out using the first two unique numbers if the array is increasing or decreasing, if its increasing, that means new numbers must not be less than the last number and if its a decreasing array, then subsequent numbers must not be greater than the previous number. Based on this conditions, we are able to do an early false return for non-monotonic arrays, and if all checks, we return a true

Complexities

Space complexity: O(1)
Time Complexity: O(N)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment