(array)
| 5 | |
| 6 | |
| 7 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected