1888. Minimum Number of Flips, Simple python solution with comments
class Solution:\n    def minFlips(self, s: str) -> int:\n        \n        n=len(s)\n        \n        \'\'\'\n            add string to it self so  "010" becom
class Solution:\n    def minFlips(self, s: str) -> int:\n        \n        n=len(s)\n        \n        \'\'\'\n            add string to it self so  "010" becomes "010010"\n            this simulates Type-1: Remove in one operation\n        \'\'\'\n        s=s+s \n        \n        diff1,diff2,result=0,0,0\n        \n        \'\'\'\n            create alternate 2 possible strings\n            which has 0 in even place other  has 1 in even place\n        \'\'\'\n        \n        alt1,alt2="",""\n        \n        for i in range(len(s)):\n            alt1+= "0" if i%2 else "1"\n            alt2+= "1" if i%2  else "0"\n        \n        \n        l=0\n        result=n\n        \n        for i in range(len(s)):\n            \n            \'\'\'\n                1.compare with alt1,alt2 and if flip necessary increment the count\n            \'\'\'\n            \n            if s[i]!=alt1[i]:\n                diff1+=1\n            \n            if s[i]!=alt2[i]:\n                diff2+=1\n            \n            \'\'\'\n                if str len greater than n then it is necessary to increment left pointer\n                but it removes lhs element (element before left pointer ) from consideration \n                which effect diff1,diff2 count\n            \'\'\'\n            if (i-l+1)>n:\n                if s[l]!=alt1[l]:\n                    diff1-=1\n                    \n                if s[l]!=alt2[l]:\n                    diff2-=1\n                \n                l+=1\n            \n            if (i-l+1)==n:\n                result=min(result,diff1,diff2)\n            \n            \n        return result\n
[]