(array)
| 4 | ''' |
| 5 | |
| 6 | def 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 | |
| 24 | def breakDirection(direction, previousInt, currentInt): |
nothing calls this directly
no test coverage detected