<p>An array is <strong>monotonic</strong> if it is either monotone increasing or monotone decreasing.</p>

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

<p>Given an integer array <code>nums</code>, return <code>true</code><em> if the given array is monotonic, or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,2,3]
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [6,5,4,4]
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,3,2]
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution {
public:
    bool isMonotonic(vector<int>& nums) {
        int n = nums.size();
        vector<bool> isInc(n, false);
        vector<bool> isDec(n, false);

        for(int i=1;i<n;i++) {
            if (nums[i] -nums[i-1] >=0) {
                isInc[i] = true;
            }
            if (nums[i] -nums[i-1] <=0) {
                isDec[i] = true;
            }
        }
        isInc[0] = true;
        isDec[0] = true;
        bool inc = true, dec = true;;
        for(int i=0;i<n;i++) {
            if (!isInc[i]) {
                inc = false;
            }
        }
        for(int i=0;i<n;i++) {
            if (!isDec[i]) {
                dec = false;
            }
        }

        if (inc ^ dec || (inc && dec)) {
            return true;
        }

        return false;
        
        
    }
};
100000