[C++] Two pointers - O(N) - very easy to grasp w/ comments
Just use two pointers i and j where \'j\' is always 2 indexes ahead of \'i\'. If s1[i]==s2[i], this implies till now both the string matches and we shall increm
Just use two pointers ```i and j``` where \'j\' is always 2 indexes ahead of \'i\'. If ```s1[i]==s2[i]```, this implies till now both the string matches and we shall increment both the pointers by 1 unit.\n\nin case ```s1[i]!=s2[i]```, we check if we can swap s1[i] with s1[j] and then, whether it makes s1[i]==s2[i] => then we move fwd as we do else string cannot be similar! hence, return false.\nif all the string is traversed, then return true!\n\n``` time - O(N) ```  \n```space - O(1) ```\n\n**PLEASE UPVOTE IF THIS SOLUTION HELPED YOU!**\nCheers! \nhappy leetcoding!\n\n# Code\n```\nclass Solution {\npublic:\n    bool canBeEqual(string s1, string s2) {\n        \n        if(s1==s2) return true;\n        int i=0; int j=2; //with a gap of 2 as given in question\n\n        while(i<4){\n            if(s1[i]==s2[i]){\n                i++; j++; continue;\n            }\n            else{\n                if(s1[i]!=s2[j]){\n                    return false; //if not equal then not possible to equate string => return false;\n                }\n                else{\n                    swap(s2[i],s2[j]);\n                    i++; j++; // increment the pointers!\n                }\n            }\n        }\n        \n        return true;\n    }\n};\n\n```
['Two Pointers', 'C++']