Push Dominoes

MediumTwo Pointerstwo pointers

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A row of dominoes stands upright, described by the string dominoes: 'L' is a domino just pushed to the left, 'R' one just pushed to the right, and '.' one still standing. Every second, each falling domino pushes its upright neighbour in the direction it is falling. An upright domino pushed from both sides in the same second stays upright. Falling or fallen dominoes put no force on dominoes that are already falling or fallen. Return a string describing the final state once nothing changes.

Examples

Input: dominoes = ".L.R...LR..L.."
Output: "LL.RR.LLRRLL.."
The middle standing domino in "R...L" receives both pushes at the same second and stays up, and the trailing dots are never reached.
Input: dominoes = "RR.L"
Output: "RR.L"
The standing domino is hit from both sides at the same moment and stays upright.

Constraints

  • 1 <= dominoes.length <= 10^5
  • `dominoes[i]` is 'L', 'R' or '.'.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More two pointers problems