bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 777. Swap Adjacent in LR String

777. Swap Adjacent in LR String

Leetcode Solutions

Check Relative Positions and Directions of L and R

  1. If the lengths of start and end are not equal, return False.
  2. Remove all 'X' characters from both start and end and compare the resulting strings. If they are not equal, return False.
  3. Iterate through both start and end strings and compare the positions of 'L' and 'R' characters.
    • For each 'L' in start, ensure its position is the same or to the left in end.
    • For each 'R' in start, ensure its position is the same or to the right in end.
  4. If all checks pass, return True. Otherwise, return False.
UML Thumbnail

Two Pointer Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...