Swap Adjacent in LR String
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given two strings start and result of equal length made of the characters 'L', 'R', and 'X'. In one move you may either replace a substring "XL" with "LX", or replace a substring "RX" with "XR".
In other words, an L can slide left into an empty X and an R can slide right into an empty X, but they can never pass through each other.
Return true if some sequence of zero or more moves transforms start into result, and false otherwise.
Examples
Constraints
- `1 <= start.length <= 10^4`
- `start.length == result.length`
- Both strings contain only `'L'`, `'R'`, and `'X'`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.