<p>Given an integer array <code>nums</code>, reorder it such that <code>nums[0] &lt; nums[1] &gt; nums[2] &lt; nums[3]...</code>.</p>

<p>You may assume the input array always has a valid answer.</p>

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

<pre>
<strong>Input:</strong> nums = [1,5,1,1,6,4]
<strong>Output:</strong> [1,6,1,5,1,4]
<strong>Explanation:</strong> [1,4,1,5,1,6] is also accepted.
</pre>

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

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

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 5000</code></li>
	<li>It is guaranteed that there will be an answer for the given input <code>nums</code>.</li>
</ul>

<p>&nbsp;</p>
<strong>Follow Up:</strong> Can you do it in <code>O(n)</code> time and/or <strong>in-place</strong> with <code>O(1)</code> extra space?
class Solution {
public:
    void wiggleSort(vector<int>& nums) {
        
        /*
        vector<int> temp(nums.size());
        int start = 0, end = nums.size() - 1;
        int mid = (end - start) / 2, index = 0;

        // sort by ascending order
        sort(nums.begin(), nums.end());

        // alternate nos from mid to start and end to mid is assigned
        while(mid >= start)
        {
            // cout << "mid:" << mid << endl;
            // cout << "start:" << mid << endl;
            // cout << "end:" << end << endl;
            // cout << "1st time --> index:" << index << endl;

            temp[index] = nums[mid];
            // cout << "temp[index]:" << temp[index] << endl;
            // cout << "nums[mid]:" << nums[mid] << endl;
            index++;
            mid--;

            // cout << "2nd time --> index:" << index << endl;

            if(index < nums.size())
            {
                temp[index] = nums[end];
                // cout << "temp[index]:" << temp[index] << endl;
                // cout << "nums[end]:" << nums[end] << endl;
                index++;
                end--;
            }

            
        }
        
        // assign the temp data to nums array
        for(index = 0; index < temp.size(); index++)
        {
            nums[index] = temp[index];
        }
        */

        vector<int> bucket(5001);
        for (int& v : nums) ++bucket[v];
        int n = nums.size();
        int j = 5000;
        for (int i = 1; i < n; i += 2) {
            while (bucket[j] == 0) --j;
            nums[i] = j;
            --bucket[j];
        }
        for (int i = 0; i < n; i += 2) {
            while (bucket[j] == 0) --j;
            nums[i] = j;
            --bucket[j];
        }
    }
};
21100