🐍 Python || Easy-understanding || well-Explained || Sliding-window
if you get any doubt feel free to ask.\n## IDEA :\n First make the copy of string ("cp" = s+s ), beacuse after performin type-1 operation maximum time we will c
if you get any doubt feel free to ask.\n## IDEA :\n* First make the copy of string ("cp" = s+s ), beacuse after performin type-1 operation maximum time we will come to end to that set of string only.\n* after this, the question becomes sliding - window problem to check which n-length substring is having highly matchable \'0\' and \'1\' (minimum fliping required).\n* create s1 and s2 string starting with \'1\' and \'0\' respectively with alternating position.\n* comparing with \'cp\' double length string when you get different character at any position then increment their result by 1 (res1 and res2 resp.).\n* when i of the loop get extended after n then start subtracting 1 from res1 and res2 when (i-n)th positions have different value.\n* Now you are sliding the window by 1 to the right with comparision.\n* In last , now u start comparing which window requires minimum flip ( res ).\n\n\'\'\'\n\n\tclass Solution:\n    def minFlips(self, s: str) -> int:\n        \n        n=len(s)\n        cp=s+s\n        s1=""\n        s2=""\n        for i in range(len(cp)):\n            if i%2==0:\n                s1+=\'1\'\n                s2+=\'0\'\n            else:\n                s1+=\'0\'\n                s2+=\'1\'\n        \n        res1=0\n        res2=0\n        res =10**6\n        for i in range(len(cp)):\n            if cp[i]!=s1[i]:\n                res1+=1\n                \n            if cp[i]!=s2[i]:\n                res2+=1\n            \n            if i>=n:\n                if cp[i-n]!=s1[i-n]:\n                    res1-=1\n                if cp[i-n]!=s2[i-n]:\n                    res2-=1\n            if i>=n-1:\n                res=min(res,res1,res2)\n        \n        return res\n            \nThank You !! \uD83E\uDD17\nIf you got help then **Do Upvote** \uD83E\uDD1E
['Sliding Window', 'Python', 'Python3']