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

Function isMonotonicAlternative

Misc/Monotonic_Array/solution.py:7–30  ·  view source on GitHub ↗
(array)

Source from the content-addressed store, hash-verified

5
6
7def isMonotonicAlternative(array):
8 # Edge condition to check for array less than 2 elements
9 if len(array) <= 2:
10 return True
11 else:
12 # Initialise the entry point
13 j = 1
14 # Monotonic Check conditions
15 # Below condition for decreasing
16 aflag = array[0] <= array[2]
17 # Condition for increasing
18 dflag = array[0] > array[2]
19 # Looping through each element in array
20 while j < len(array):
21 # Decreasing check
22 if array[j - 1] <= array[j] and aflag:
23 j += 1
24 # Increasing check
25 elif array[j - 1] >= array[j] and dflag:
26 j += 1
27 # If not both then break and return false
28 else:
29 return False
30 return True
31

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected