Python Regex and Recursion/Iterative versions
The recursive solution is easy to understand, but the recursive version fails in OJ for huge strings with maximum recursion depth exceeded, hence I converted it
The recursive solution is easy to understand, but the recursive version fails in OJ for huge strings with maximum recursion depth exceeded, hence I converted it to iterative version, which gets accepted easily.\n\nLogic:\n\nIf the current character matches, we just increment i.\nIf the current character does not match:\nthen we are trying to find patterns XXXL or RRRX which is basically [X]+L  or [R]+X in regex form.\nSay XXXL matches the start string, then we just make sure that end string starts with L, and we convert the start string to XXX + remaining  and proceed with the rest of the string\n\nIterative version:\n```\ndef canTransform(self, start, end):\n        if start == end: return True\n        i = 0\n        while i < len(start):\n            if start[i] == end[i]:\n                i += 1\n            else:\n                new_se = self.get_transformed(start[i:], end[i:], 'X+L') or self.get_transformed(start[i:], end[i:], 'R+X')\n                if not new_se: return False\n                start, end, i = new_se[0], new_se[1], 0\n        return True\n\n    def get_transformed(self, start, end, regex):\n        m = re.match(regex, start)\n        if m and end[0] == start[m.end() - 1]:\n            return (start[0] * (m.end() - 1)) + start[m.end():], end[1:]\n        return None\n```\n\nRecursive version:\n\n    def canTransform(self, start, end):\n        if start == end: return True\n\n        if start[0] == end[0]:\n            return self.canTransform(start[1:], end[1:])\n\n        new_se = self.get_transformed(start, end, 'X+L') or self.get_transformed(start, end, 'R+X')\n        if new_se: return self.canTransform(new_se[0], new_se[1])\n\n        return False\n    \n    def get_transformed(self, start, end, regex):\n        m = re.match(regex, start)\n        if m and end[0] == start[m.end()-1]:\n            return (start[0] * (m.end()-1)) + start[m.end():], end[1:]\n        return None
[]