FunctionRacerProblemsRace

Falling Dominoes

MediumStringsPython, JavaScript, TypeScript, Java, C++

Dominoes stand in a row. At the start row[i] is L if domino i is pushed to the left, R if it is pushed to the right, and . if it is left standing.

Every second, each domino that is falling to the left knocks over the standing domino on its left, and each domino falling to the right knocks over the standing one on its right. A standing domino that is hit from both sides in the same second stays standing for good. A domino that is already falling is never changed.

Return the row when nothing moves any more, written with the same three characters.

Example 1

row ".R.....L."
returns ".RRR.LLL."

The R knocks over the two dominoes after it, the L the one before it. The domino in the middle is hit from both sides at once.

Example 2

row "L.R..."
returns "L.RRRR"

The first domino falls left onto nothing, and the R pushes over everything to its right.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems