✅✅Faster || Easy To Understand || C++ Code || 👌👌👌
Using Sliding Window\n\n Time Complexity : O(N)\n\n Space Complexity : O(N)\n\n\n\n\nclass Solution {\npublic:\n    int minFlips(string str) {\n        \n      
* ***Using Sliding Window***\n\n* ***Time Complexity : O(N)***\n\n* ***Space Complexity : O(N)***\n\n\n\n```\nclass Solution {\npublic:\n    int minFlips(string str) {\n        \n        int n = str.size();\n        \n        str += str;    // concatenate the string with itself instead of moving one element from start to end\n        \n        string target_1 = "";  // it may be like "010101010101" alternating string\n         \n        string target_2 = "";  // it may be like "101010101010" alternating string\n        \n        // fill the target_1 and target_2\n        \n        for(int i = 0; i < str.size(); i++)\n        {\n            if(i % 2 == 0)\n            {\n                target_1 += \'0\';\n                \n                target_2 += \'1\';\n            }\n            else\n            {\n                target_1 += \'1\';\n                \n                target_2 += \'0\';\n            }\n        }\n        \n        int diff_1 = 0;   // will store the no of different characters in window from target_1\n        \n        int diff_2 = 0;   // will store the no of different characters in window from target_2\n        \n        int mini = INT_MAX;\n        \n        // apply sliding window, window length will be n\n        \n        for(int i = 0; i < str.size(); i++)\n        {\n            if(i < n)\n            {\n                if(str[i] != target_1[i])\n                {\n                    diff_1++;\n                }\n                \n                if(str[i] != target_2[i])\n                {\n                    diff_2++;\n                }\n            }\n            else\n            {\n                // update our result\n                \n                mini = min({mini, diff_1, diff_2});\n                \n                // removing one character from window from start\n                \n                if(str[i - n] != target_1[i - n])\n                {\n                    diff_1--;\n                }\n                \n                if(str[i - n] != target_2[i - n])\n                {\n                    diff_2--;\n                }\n                \n                // adding one character to window at end\n                \n                if(str[i] != target_1[i])\n                {\n                    diff_1++;\n                }\n                \n                if(str[i] != target_2[i])\n                {\n                    diff_2++;\n                }\n            }\n        }\n        \n        mini = min({mini, diff_1, diff_2});\n        \n        return mini;\n    }\n};\n```
['C', 'Sliding Window']