<p>Given an array <code>nums</code> of integers, a <em>move</em>&nbsp;consists of choosing any element and <strong>decreasing it by 1</strong>.</p>

<p>An array <code>A</code> is a&nbsp;<em>zigzag array</em>&nbsp;if either:</p>

<ul>
	<li>Every even-indexed element is greater than adjacent elements, ie.&nbsp;<code>A[0] &gt; A[1] &lt; A[2] &gt; A[3] &lt; A[4] &gt; ...</code></li>
	<li>OR, every odd-indexed element is greater than adjacent elements, ie.&nbsp;<code>A[0] &lt; A[1] &gt; A[2] &lt; A[3] &gt; A[4] &lt; ...</code></li>
</ul>

<p>Return the minimum number of moves to transform the given array <code>nums</code> into a zigzag array.</p>

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

<pre>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can decrease 2 to 0 or 3 to 1.
</pre>

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

<pre>
<strong>Input:</strong> nums = [9,6,1,6,2]
<strong>Output:</strong> 4
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
</ul>

class Solution {
public:
    int movesToMakeZigzag(vector<int>& nums) {
        int n=nums.size();
        if(n==1) return 0;
        int even=0;
        int odd=0;
        //vector<int>& nums1=nums;
        for(int i=0;i<n;i+=2){
            int temp=0;
            if(i+1<n && nums[i+1]>=nums[i]){
                temp=nums[i+1]-nums[i]+1;
            }
            if(i+2<n && nums[i+1]>=nums[i+2]){
                temp=max(temp,nums[i+1]-nums[i+2]+1);
            }
            even+=temp;
        }
        int i;
        for( i=1;i<n;i+=2){
            int temp=0;
            if(i-1>=0 && nums[i-1]>=nums[i]){
                temp=nums[i-1]-nums[i]+1;    
            }
            if(i-2>=0 && nums[i-1]>=nums[i-2]){
                    temp=max(temp,nums[i-1]-nums[i-2]+1);
                }
            odd+=temp;
        }
        if(i==n){
            if(nums[i-1]>=nums[i-2])
                odd+=nums[i-1]-nums[i-2]+1;
        }
        return min(even,odd);
    }
};
8900