Welcome folks today in this post we will be checking whether an array is monotonic or not
in python. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Python3 program to find sum in Nth group # Check if given array is Monotonic def isMonotonic(A): return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or all(A[i] >= A[i + 1] for i in range(len(A) - 1))) # Driver program A = [6, 5, 4, 4] # Print required result print(isMonotonic(A)) # This code is written by |
Now if you execute the python
script by typing the below command as shown below
python app.py