`Input: start = "RXXLRXRXL", end = "XRLXXRRLX"Output: trueExplanation:We can transform start to end following these steps:RXXLRXRXL ->XRXLRXRXL ->XRLXRXRXL ->XRLXXRRXL ->XRLXXRRLX`
`Input: start = "LLR", end = "RRL"Output: false`
`Input: start = "XLLR", end = "LXLX"Output: false`

# Explanation

`class Solution:    def canTransform(self, start: str, end: str) -> bool:        if len(start) != len(end): return False                # check L R orders are the same        if start.replace('X','') != end.replace('X', ''): return False                n = len(start)        Lstart = [i for i in range(n) if start[i] == 'L']        Lend = [i for i in range(n) if end[i] == 'L']                Rstart = [i for i in range(n) if start[i] == 'R']        Rend = [i for i in range(n) if end[i] == 'R']# check L positions are correct        for i, j in zip(Lstart, Lend):            if i < j:                return False                    # check R positions are correct        for i, j in zip(Rstart, Rend):            if i > j:                return False                    return True`

--

--

10x your algorithm interview prep speed. Take the 5-minute quiz: https://algo.monster/evaluator

Love podcasts or audiobooks? Learn on the go with our new app.

## Algo.Monster

10x your algorithm interview prep speed. Take the 5-minute quiz: https://algo.monster/evaluator