[C++] Strict one pass, O(n) time, O(1) space
\n// IDEA:\n//   1. Observed that for a valid result:\n//      a. For each \'R\' in start, you will have to shift it to right\n//         without meeting any \'
```\n// IDEA:\n//   1. Observed that for a valid result:\n//      a. For each \'R\' in start, you will have to shift it to right\n//         without meeting any \'L\' in either start or end\n//      b. Similar to a, For each \'L\' in end, you will have to shift it\n//         to right without meeting any \'R\' in either start or end\n//      c. The reason why they cannot meet is because if \'L\' and \'R\' meet\n//         they cannot cross eachother to their desired position.\n//      d. a special case is:\n//           s: XXLL\n//           e: LLXX\n//         observed that rule a and b still cannot be broken, so use a count\n//         to store the Ls / Rs that needs to be shifted\n//\n//   3. So for our solution, we use a one pass for loop from left to right,\n//      whenever we meet a \'R\' in start or \'L\' in end, mark it. Keep traversing\n//      until we meet an \'R\' or \'L\' in the opposing string. If a false condition\n//      is encoutnered, return false. As last, check if there is a buffered \'L\'\n//      or \'R\', if not, the two strings are valid.\n//\n//   4. Complexity analysis:\n//      O(n) time due to for loop checking each character in start and end\n//      O(1) space, only two variables c and cnt\n\nclass Solution {\npublic:\n    bool canTransform(string s, string e) {\n        char c = \'X\'; // current buffered \'L\' or \'R\'\n        int cnt = 0;  // number of buffered \'L\' or \'R\'\n\n        // One pass for loop\n        for (int i = 0; i < s.size(); i++) {\n            \n            // Check if \'L\' or \'R\' is buffered\n            if (c == \'X\') {\n                \n                // continue if the two characters are the same\n                if (s[i] == e[i]) continue;\n                \n                // invalid position of \'L\' / \'R\', because\n                // e[i] should have a buffered \'L\' before an \'L\' in s[i]\n                // s[i] should have a buffered \'R\' before an \'R\' in e[i]\n                if (s[i] == \'L\' || e[i] == \'R\') return false;\n                \n                // valid position of \'L\' / \'R\', buffer them\n                if (s[i] == \'R\') {\n                    if (e[i] == \'L\') return false;\n                    c = s[i];\n                    cnt++;\n                } else if (e[i] == \'L\') {\n                    if (s[i] == \'R\') return false;\n                    c = e[i];\n                    cnt++;\n                }\n            } else {\n                if (s[i] == \'X\' && e[i] == \'X\') continue;\n                switch (c) {\n                    case \'L\':\n                        if (s[i] == \'R\' || e[i] == \'R\') return false; // refer to description 1c\n                        if (e[i] == \'L\') cnt++;\n                        if (s[i] == \'L\') cnt--;\n                        break;\n                    case \'R\':\n                        if (s[i] == \'L\' || e[i] == \'L\') return false; // refer to description 1c\n                        if (s[i] == \'R\') cnt++;\n                        if (e[i] == \'R\') cnt--;\n                        break;\n                    default:\n                        return false; // catch exception\n                }\n                // clear buffer if the count is 0\n                if (cnt == 0) c = \'X\';\n            }\n        }\n        // Check if the buffer is cleared\n        return c == \'X\';\n    }\n};\n```
['C', 'C++']