#777
Swap Adjacent in LR String
expert · 1090 · lc medium +32 · verified · 37.9% accepted · 1,334 likes · top 16%
Description
In a string of 'L', 'R', and 'X' characters, 'L' can slide left over 'X' (replacing "XL" with "LX") and 'R' can slide right over 'X' (replacing "RX" with "XR"). Neither 'L' nor 'R' can pass through each other.
Given strings start and result, return True if start can be transformed into result by any sequence of such moves.
Example 1:
Input: start = "RXXLRXRXL", result = "XRLXXRRLX"
Output: true
Explanation: We can transform start to result following these steps:
RXXLRXRXL ->
XRXLRXRXL ->
XRLXRXRXL ->
XRLXXRRXL ->
XRLXXRRLX
Example 2:
Input: start = "X", result = "L"
Output: false
Code
1
2
3