bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
MediumGraphsLC 777

Swap Adjacent in LR String

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 end, return True if and only if there exists a sequence of moves to transform one string to the other.

Asked at 2 companies
BytedanceGoogle
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode