An array is monotonic if it is either monotone increasing or monotone decreasing.

An array nums is monotone increasing if for all i &lt;= j, nums[i] &lt;= nums[j]. An array nums is monotone decreasing if for all i &lt;= j, nums[i] &gt;= nums[j].

Given an integer array nums, return true if the given array is monotonic, or false otherwise.

&nbsp;
Example 1:

Input: nums = [1,2,2,3]
Output: true


Example 2:

Input: nums = [6,5,4,4]
Output: true


Example 3:

Input: nums = [1,3,2]
Output: false


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-105 &lt;= nums[i] &lt;= 105


class Solution:
    def isMonotonic(self, nums: List[int]) -> bool:
        counter = 0
        for i in range(len(nums) - 1):
            if nums[i] >= nums[i + 1]:
                counter += 1
        if counter == len(nums) - 1:
            return True
        counter = 0
        for i in range(len(nums) - 1):
            if nums[i] <= nums[i + 1]:
                counter += 1
        if counter == len(nums) - 1:
            return True
        return False
class Solution {
    public boolean isMonotonic(int[] nums) {
        if(nums[0]<nums[nums.length-1]){
            for(int i=0;i<nums.length-1;i++){
            if(!(nums[i]<=nums[i+1])) return false;
        }
        }else{
            for(int i=0;i<nums.length-1;i++){
            if(!(nums[i]>=nums[i+1])) return false;
        }
        }
        return true;
    }
}
class Solution {
public:
    bool isMonotonic(vector<int>& nums) {
        auto i = find_if_not(begin(nums), end(nums), [&](int a) {return a == nums.front();});
        auto j = find_if_not(rbegin(nums), rend(nums), [&](int a) {return a == nums.back();});
        return is_sorted(--i, end(nums)) or is_sorted(--j, rend(nums));
    }
};
var isMonotonic = function(nums) {
    let increasingCount = 0;
    let decreasingCount = 0;
    for(let i = 1; i < nums.length; i++){
        if(nums[i] > nums[i-1]){
            increasingCount++;
        }else if(nums[i] < nums[i-1]){
            decreasingCount++;
        }
    }
    
    return !(increasingCount && decreasingCount);
};
Monotonic Array