Skip to main content
LeetCode 777, Medium. Topics: Two Pointers, String. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 31 parametrized pytest cases, and a playground notebook:

Problem

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.

Examples

Constraints

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

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026