<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:
    def wiggleSort(self, nums: list[int]) -> None:
        # Sort the numbers
        nums.sort()
        n = len(nums)
        
        # Create a new array to hold the rearranged elements
        sorted_nums = nums[:]
        
        # Rearrange the elements
        # Use two pointers to fill the elements
        left, right = (n - 1) // 2, n - 1
        for i in range(n):
            if i % 2 == 0:
                nums[i] = sorted_nums[left]
                left -= 1
            else:
                nums[i] = sorted_nums[right]
                right -= 1

# Example usage:
sol = Solution()

nums1 = [1, 5, 1, 1, 6, 4]
sol.wiggleSort(nums1)
print(nums1)  # Output: [1, 6, 1, 5, 1, 4] or similar valid wiggle sort

nums2 = [1, 3, 2, 2, 3, 1]
sol.wiggleSort(nums2)
print(nums2)  # Output: [2, 3, 1, 3, 1, 2] or similar valid wiggle sort

nums3 = [4, 5, 5, 6]
sol.wiggleSort(nums3)
print(nums3)  # Output: [5, 6, 4, 5] or similar valid wiggle sort

19700