Transform L/R Pieces With Barriers
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'|'.