777. Swap Adjacent in LR String
Practice Swap Adjacent in LR String for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Strings start and result consist of 'L', 'R' and 'X'. One move either replaces an occurrence of "XL" with "LX" or replaces an occurrence of "RX" with "XR". Return true if start can be turned into result with any number of moves.
(In other words, L slides left over Xs and R slides right over Xs, and they never cross each other.)
Example
start = "RXXLRXRXL", result = "XRLXXRRLX" -> true
start = "X", result = "L" -> false
Constraints
- 1 <= start.length <= 10^4
- start.length == result.length
- Both strings consist of 'L', 'R' and 'X'