[Python] Not sliding window, Just odd even count
The main concept behind this solution is to store count of zeroes and ones at odd and even places, for that I have declared odd and even array of size 2 where p
The main concept behind this solution is to store count of zeroes and ones at odd and even places, for that I have declared odd and even array of size 2 where position 0 represent the count of 0\'s. \nto get alternating sequence, there are two different possibilities:\n1) Starting with 0\n2) Starting with 1\n\nThe strings which start with 0 means 0\'s are at even position and 1\'s are at odd position that means we need to flip all the 1\'s at even position and all the 0\'s at odd position. If we have 3 zeroes at even position and total number of evenpositions are 5, then the required flips(1->0) are (5-3)=2 that means 2 ones are needed to be flipped. and same way the number of flips (0 -> 1) for odd position is (total_odd_position_count - odd[1])\n\n\nIf the length of string is even, on every operation-1 the oddcount is changed to even and even count is changed to odd, so the ans would not change.\nIf the length of string is odd, on every operation-1, the odd count and even count swaps and the even count of digit at starting position decreases whereas odd count increases.\n\nCode:\n\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        s=[int(i) for i in s] #converting every binary digit into integer\n        odd=[0,0] #this array stores count of 0\'s at oddposition in odd[0] and 0\'s at evenposition at odd[1]\n        even=[0,0] #similar to odd\n        for i in range(len(s)):\n            if(i%2==0):\n                even[s[i]]+=1 #incrementing even position (0 or 1) count\n            else:\n                odd[s[i]]+=1 #incrementing odd position (0 or 1) count\n        evencount=(len(s)+1)//2 #total evenposition count\n        oddcount=len(s)//2 #total oddposition count\n\t\t\n\t\t#ans = minimum flips required of strings starting with 0 and strings starting with 1\n        ans=min((evencount-even[0])+(oddcount-odd[1]),(evencount-even[1])+(oddcount-odd[0]))\n        if(len(s)%2==0):return ans \n        for i in range(len(s)):\n\t\t\teven[s[i]]-=1 #even count of the digit decreases\n            odd[s[i]]+=1  #odd count of the digit increases\n            odd,even=even,odd #odd and even gets swapped\n            ans=min(evencount-even[0]+oddcount-odd[1],evencount-even[1]+oddcount-odd[0],ans) \n        return ans\n```
[]