<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
        oddDict = {}
        evenDict = {}

        evenLength = len(nums) // 2 if len(nums) % 2 == 0 else (len(nums) // 2) + 1
        oddLength = len(nums) // 2

        evenList = []
        oddList = []

        for i in range(len(nums)):
            if i % 2 == 0:
                dictVal = evenDict.get(nums[i], 0)
                dictVal += 1
                evenDict[nums[i]] = dictVal
                evenList.append(nums[i])
            else:
                dictVal = oddDict.get(nums[i], 0)
                dictVal += 1
                oddDict[nums[i]] = dictVal
                oddList.append(nums[i])

        print(evenList)
        print(oddList)

        oddFirst = None
        oddSecond = None
        evenFirst = None
        evenSecond = None

        for key in oddDict.keys():
            if not oddFirst:
                oddFirst = key
            elif oddDict.get(oddFirst) < oddDict.get(key):
                oddSecond = oddFirst
                oddFirst = key
            elif not oddSecond:
                oddSecond = key
            elif oddDict.get(oddSecond) < oddDict.get(key):
                oddSecond = key


        for key in evenDict.keys():
            if not evenFirst:
                evenFirst = key
            elif evenDict.get(evenFirst) < evenDict.get(key):
                evenSecond = evenFirst
                evenFirst = key
            elif not evenSecond:
                evenSecond = key
            elif evenDict.get(evenSecond) < evenDict.get(key):
                evenSecond = key


        oddFirstChanges = oddLength - oddDict.get(oddFirst)
        oddSecondChanges = None if not oddSecond else oddLength - oddDict.get(oddSecond)
        evenFirstChanges = evenLength - evenDict.get(evenFirst)
        evenSecondChanges = None if not evenSecond else evenLength - evenDict.get(evenSecond)

        if not oddSecond and not evenSecond:
            if oddFirst != evenFirst:
                return 0
            else:
                return oddDict.get(oddFirst)
        
        if oddFirst != evenFirst:
            return oddFirstChanges + evenFirstChanges

        if oddFirst == evenFirst:
            switchEven = None
            switchOdd = None
            if evenSecondChanges:
                switchEven = oddFirstChanges + evenSecondChanges
            if oddSecondChanges:
                switchOdd = oddSecondChanges + evenFirstChanges
            
            if switchEven and switchOdd:
                return min(switchEven, switchOdd)
            elif switchEven:
                return switchEven
            else:
                return switchOdd

        # if oddFirst == evenFirst:
        #     if evenDict.get(evenFirst) > oddDict.get(oddFirst):
        #         oddChanges = oddLength - oddDict.get(oddSecond)
        #         evenChanges = evenLength - evenDict.get(evenFirst)
        #         return oddChanges + evenChanges
        #     elif evenDict.get(evenFirst) == oddDict.get(oddFirst):
        #         if evenSecond and (not oddSecond or evenDict.get(evenSecond) > oddDict.get(oddSecond)):
        #             oddChanges = oddLength - oddDict.get(oddFirst)
        #             evenChanges = evenLength - evenDict.get(evenSecond)
        #             return oddChanges + evenChanges
        #         else:
        #             oddChanges = oddLength - oddDict.get(oddSecond)
        #             evenChanges = evenLength - evenDict.get(evenFirst)
        #             return oddChanges + evenChanges
        #     else:
        #         oddChanges = oddLength - oddDict.get(oddFirst)
        #         evenChanges = evenLength - evenDict.get(evenSecond)
        #         return oddChanges + evenChanges
        
941