<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <code>n</code> positive integers.</p>

<p>The array <code>nums</code> is called <strong>alternating</strong> if:</p>

<ul>
	<li><code>nums[i - 2] == nums[i]</code>, where <code>2 &lt;= i &lt;= n - 1</code>.</li>
	<li><code>nums[i - 1] != nums[i]</code>, where <code>1 &lt;= i &lt;= n - 1</code>.</li>
</ul>

<p>In one <strong>operation</strong>, you can choose an index <code>i</code> and <strong>change</strong> <code>nums[i]</code> into <strong>any</strong> positive integer.</p>

<p>Return <em>the <strong>minimum number of operations</strong> required to make the array alternating</em>.</p>

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

<pre>
<strong>Input:</strong> nums = [3,1,3,2,4,3]
<strong>Output:</strong> 3
<strong>Explanation:</strong>
One way to make the array alternating is by converting it to [3,1,3,<u><strong>1</strong></u>,<u><strong>3</strong></u>,<u><strong>1</strong></u>].
The number of operations required in this case is 3.
It can be proven that it is not possible to make the array alternating in less than 3 operations. 
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,2,2,2]
<strong>Output:</strong> 2
<strong>Explanation:</strong>
One way to make the array alternating is by converting it to [1,2,<u><strong>1</strong></u>,2,<u><strong>1</strong></u>].
The number of operations required in this case is 2.
Note that the array cannot be converted to [<u><strong>2</strong></u>,2,2,2,2] because in this case nums[0] == nums[1] which violates the conditions of an alternating array.
</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>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def minimumOperations(self, nums: List[int]) -> int:
        n = len(nums)
        if n == 1:
            return 0
        
        # Count the occurrences of each number at even and odd indices
        even_count = {}
        odd_count = {}
        for i in range(0, n, 2):
            if nums[i] in even_count:
                even_count[nums[i]] += 1
            else:
                even_count[nums[i]] = 1
            
        for i in range(1, n, 2):
            if nums[i] in odd_count:
                odd_count[nums[i]] += 1
            else:
                odd_count[nums[i]] = 1
        
        # Find the most frequent and second most frequent numbers at even and odd indices
        def find_top_two(count):
            max_freq = 0
            max_num = 0
            second_max_freq = 0
            second_max_num = 0
            for num, freq in count.items():
                if freq > max_freq:
                    second_max_freq = max_freq
                    second_max_num = max_num
                    max_freq = freq
                    max_num = num
                elif freq > second_max_freq:
                    second_max_freq = freq
                    second_max_num = num
            return (max_num, max_freq), (second_max_num, second_max_freq)
        
        (even_top_num, even_top_freq), (even_second_top_num, even_second_top_freq) = find_top_two(even_count)
        (odd_top_num, odd_top_freq), (odd_second_top_num, odd_second_top_freq) = find_top_two(odd_count)
        
        # Calculate the minimum number of operations required
        if even_top_num != odd_top_num:
            return n - even_top_freq - odd_top_freq
        else:
            return n - max(even_top_freq + odd_second_top_freq, even_second_top_freq + odd_top_freq)
30700