Optimal Solution
Greedy Approach\nGiven problem states minimum steps to convert the XO string to only Os.\nAlso, under the constraint of the move described,\nif we choose an ind
# Greedy Approach\nGiven problem states minimum steps to convert the XO string to only Os.\nAlso, under the constraint of the **move** described,\nif we choose an index for operating, we can absolutely assure that the character in the next 2 consecutive indices will also get resolved to O within that **move**. (making 3 consecutive indices)\nSo, our approach is such that we always search for the closest X position and operate. (OKAY!)\nNow,\nwe don\'t simply iterate from next index, but move our pointer ahead 3 indices of current position, as the 3 consecutive are already considered to be converted to O (By definition of the **move**).\n\nBesides we make sure to avoid index overflow by checking index < length in every iteration.\n\n```\nclass Solution {\npublic:\n    int minimumMoves(string s) {\n        int n=s.size();\n        int res=0,i=0;\n        while(i<n){\n            while(s[i]==\'O\')i++;//greedily moving to next X position\n            if(i>=n)break; //breaks if pointer exceeds array length \n            res++;\n            i+=3;\n        }\n        return res;\n    }\n};\n```\n
['String']