JAVA | Sliding Window | Video solution ✅
Please Upvote :D\n\nclass Solution {\n    public int minFlips(String s) {\n        StringBuilder sb = new StringBuilder(s).append(s);\n\n        StringBuilder a
### **Please Upvote** :D\n```\nclass Solution {\n    public int minFlips(String s) {\n        StringBuilder sb = new StringBuilder(s).append(s);\n\n        StringBuilder alt1 = new StringBuilder();\n        StringBuilder alt2 = new StringBuilder();\n\n        for (int i = 0; i < sb.length(); i++) {\n            if (i % 2 == 0) {\n                alt1.append(0);\n                alt2.append(1);\n            }\n            else {\n                alt1.append(1);\n                alt2.append(0);\n            }\n        }\n\n        int diff1 = 0, diff2 = 0;\n        int l = 0;\n\n        int res = sb.length();\n\n        for (int r = 0; r < sb.length(); r++) {\n            if (alt1.charAt(r) != sb.charAt(r)) diff1++;\n            if (alt2.charAt(r) != sb.charAt(r)) diff2++;\n\n            if (r - l + 1 > s.length()) {\n                if (alt1.charAt(l) != sb.charAt(l)) diff1--;\n                if (alt2.charAt(l) != sb.charAt(l)) diff2--;\n                l++;\n            }\n\n            if (r - l + 1 == s.length()) {\n                res = Math.min(res, Math.min(diff1, diff2));\n            }\n        }\n\n        return res;\n    }\n}\n\n// TC: O(n), SC: O(1)\n```\n[Watch this video to understand the approach](https://www.youtube.com/watch?v=MOeuK6gaC2A)
['Sliding Window', 'Java']