MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / isMonotonic

Function isMonotonic

Misc/Monotonic_Array/solution2.py:6–21  ·  view source on GitHub ↗
(array)

Source from the content-addressed store, hash-verified

4'''
5
6def isMonotonic(array):
7 # Edge condition to check for array less than 2 elements
8 if len(array) <= 2:
9 return True
10 # Determining weather increasing or decreasing
11 direction = array[1] - array[0]
12 # Looping through all elements in array
13 for i in range(2, len(array)):
14 # Check if direction is maintained
15 if direction == 0:
16 direction = array[i] - array[i - 1]
17 continue
18 # If direction is changed break and return false
19 if breakDirection(direction, array[i - 1], array[i]):
20 return False
21 return True
22
23
24def breakDirection(direction, previousInt, currentInt):

Callers

nothing calls this directly

Calls 1

breakDirectionFunction · 0.85

Tested by

no test coverage detected