[
array
]
BinarySearch 0019 Strictly Increasing or Strictly Decreasing
Problem statement
https://binarysearch.com/problems/Strictly-Increasing-or-Strictly-Decreasing/
Solution
Almost the same as Leetcode 0896 Monotonic Array.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, A):
inc = dec = True
for i in range(len(A) - 1):
if A[i] >= A[i+1]: inc = False
if A[i] <= A[i+1]: dec = False
return inc or dec