Medium · Strings

Swap Adjacent in LR String

Given two equal-length strings start and target made of 'L', 'R' and 'X', where one move replaces an occurrence of "XL" with "LX" or of "RX" with "XR", return true if some sequence of moves turns start into target, otherwise false.

Examples

Example 1

{
  "start": "RXXLRXRXL",
  "target": "XRLXXRRLX"
}

Output: true

Example 2

{
  "start": "XL",
  "target": "LX"
}

Output: true

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems