Transform L/R Pieces on a Circular Board
Updated
Problem statement
start and target describe boards of equal length. Each cell is 'L', 'R', or '.'.
- An
'L'piece moves only left. - An
'R'piece moves only right. - A piece may move any positive distance through empty cells, but it may not pass through or land on another piece.
- Pieces may move in any order.
If circular is false, pieces cannot leave the board. If circular is true, the board wraps: moving left from index 0 continues at index n - 1, and moving right from index n - 1 continues at index 0.
Return whether start can be transformed into target.
Function
canTransformLRPieces(start: String, target: String, circular: boolean) → booleanExamples
Example 1
start = ".L..R..R."target = "L......RR"circular = falsereturn = trueThe nonempty piece order is unchanged. L moves from 1 to 0, while the two R pieces move from 4 and 7 to 7 and 8.
Example 2
start = "L.."target = "..L"circular = truereturn = trueThe L piece leaves index 0 through the left boundary and re-enters at index 2.
Example 3
start = "RL.."target = "LR.."circular = truereturn = falseEach piece is immediately blocked in its allowed direction. Reaching the target would require the two pieces to cross.
Constraints
1 <= start.length == target.length <= 3000.- Both strings contain only
'L','R', and'.'.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Palindrome Match PercentageApple · ONSITE INTERVIEW
- Add Signed Character ArraysByteDance · PHONE SCREEN
- Next Palindrome NumberBenchling · PHONE SCREEN
- Parse, Normalize, and Combine PolynomialsSquarepoint Capital · PHONE SCREEN
- Alphabetically Maximum SubstringOracle · PHONE SCREEN
- Integer to English Words: Up to 20 DigitsPeopleStrong · ONSITE INTERVIEW
- Signed Digit Partitions Reaching a TargetMeta · PHONE SCREEN
- Longest Properly Closed Bracket RunAdobe · PHONE SCREEN
- Indexed Proximity SearchStripe · PHONE SCREEN
- Run-Length Encoding and DecodingAirbnb · PHONE SCREEN