Transform L/R Pieces With Barriers
Updated
Problem statement
start and target are boards of equal length containing four characters:
'L'is a piece that moves only left.'R'is a piece that moves only right.'.'is an empty cell.'|'is an immovable barrier.
A piece may move through empty cells, but it may not pass through another piece or a barrier. Barriers never move. Pieces may move in any order.
Return whether start can be transformed into target.
Function
canTransformWithBarriers(start: String, target: String) → booleanExamples
Example 1
start = ".L.|R.."target = "L..|..R"return = trueWithin the left segment, L moves from index 1 to 0. Within the right segment, R moves from index 4 to 6. Neither piece crosses the barrier at index 3.
Example 2
start = "R..|..L"target = "..R|L.."return = trueR moves right inside the first segment and L moves left inside the second segment.
Example 3
start = "R.|..."target = "..|R.."return = falseThe R piece would have to cross the fixed barrier at index 2.
Constraints
1 <= start.length == target.length <= 100000.- 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
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Reverse Words in a StringAgoda · PHONE SCREENAgoda interview questions
- Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
- Shortest Way to Form a Target StringPinterest · PHONE SCREENPinterest interview questions
- Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Snake-Case Iterator to Camel CaseNavan · PHONE SCREENNavan interview questions
- Reverse Word Order In PlaceMicrosoft · PHONE SCREENMicrosoft interview questions
- String CompressionBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Compare Version NumbersInMobi · PHONE SCREENInMobi interview questions