<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:
        if len(nums) <= 1:
            return 0

        # Frequency dictionaries for odd and even indices
        freq1 = defaultdict(int)
        freq2 = defaultdict(int)
        
        # Separate frequencies for odd and even index elements
        for i, n in enumerate(nums):
            if i % 2 == 1:
                freq1[n] += 1
            else:
                freq2[n] += 1

        # Get the two most frequent values in freq1 and freq2
        max_1, second_max_1 = self.get_top_two(freq1)
        max_2, second_max_2 = self.get_top_two(freq2)

        # Case when the most frequent values are the same
        if max_1 == max_2:
            # If they clash, take the next best alternative for one of them
            change_if_choose_max1 = len(nums) // 2 - freq1[max_1] + (len(nums) + 1) // 2 - freq2.get(second_max_2, 0)
            change_if_choose_max2 = (len(nums) + 1) // 2 - freq2[max_2] + len(nums) // 2 - freq1.get(second_max_1, 0)
            return min(change_if_choose_max1, change_if_choose_max2)
        else:
            # No clash, calculate the minimal changes
            return (len(nums) // 2 - freq1[max_1]) + ((len(nums) + 1) // 2 - freq2[max_2])

    def get_top_two(self, freq):
        if not freq:
            return None, None
        sorted_freq = sorted(freq.items(), key=lambda x: -x[1])
        max_1 = sorted_freq[0][0]
        second_max_1 = sorted_freq[1][0] if len(sorted_freq) > 1 else None
        return max_1, second_max_1
933