Skip to content

Practice Swap Adjacent in LR String

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#777
LeetCode Problem

Swap Adjacent in LR String

Problem Statement

In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string result, return True if and only if there exists a sequence of moves to transform start to result.

Source: Swap Adjacent in LR String on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
start = "RXXLRXRXL", result = "XRLXXRRLX"
Output
true

# Example 2

Input
start = "X", result = "L"
Output
false

Constraints

1 <= start.length <= 10^4
start.length == result.length
Both start and result will only consist of characters in 'L', 'R', and 'X'.

Related LeetCode Problems

Practice more problems similar to Swap Adjacent in LR String.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.