Swap Adjacent in LR String
Updated
Problem statement
You are given two strings start and result of the same length. Every character is 'L', 'R' or 'X'.
In one move you may do either of these:
- replace one occurrence of
"XL"with"LX", or - replace one occurrence of
"RX"with"XR".
Return true if some sequence of moves (possibly none) turns start into result, and false otherwise.
The problem statement continues
ProExamples
Example 1
start = "XRXXLX"result = "XXRLXX"return = trueMove the R one step right, then the L one step left: "XRXXLX" becomes "XXRXLX" ("RX" to "XR"), then "XXRLXX" ("XL" to "LX").
FastPrep Pro
Reported in 1 Google interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week
More Google Onsite Interview questions
- Count Winning Dice Face PairsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find a Failing Test PairONSITE INTERVIEW · Seen Nov 2026
- Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Shortest Deletion for Distinct CharactersOracle · ONSITE INTERVIEWOracle interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Reverse File LinesCitadel · ONSITE INTERVIEWCitadel interview questions
- Longest Palindromic Substring LengthMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- All Distinct Palindromic SubstringsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- String CompressionBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Palindromic SubstringPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Strings at Most One Edit ApartExpedia · ONSITE INTERVIEWExpedia interview questions
- String CompressionShnoor International · ONSITE INTERVIEW
- Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions