896-Monotonic-Array

Sat 17 May 2025

https://leetcode.com/problems/monotonic-array

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def isMonotonic(self, A: List[int]) -> bool:
    increasing = True
    decreasing = True

    for i in range(1, len(A)):
      increasing &= A[i - 1] <= A[i]
      decreasing &= A[i - 1] >= A[i]

    return increasing or decreasing
new Solution().isMonotonic()

Score: 5

Category: leetcode