Skip to main content
Back to problems
Leetcode
Medium
Arrays
Strings
Simulation
Greedy
Google
Meta
Push Dominoes

Simulate how a row of dominoes falls after some are initially pushed left or right.

Acceptance 0%
Problem Statement

You are given a string representing a row of dominoes. Each character is one domino state:

  • L means the domino has been pushed to the left
  • R means the domino has been pushed to the right
  • . means the domino is standing upright

Dominoes continue falling in the direction they are pushed. A standing domino will be pushed by a neighboring falling domino if the force reaches it first. If equal force reaches a domino from both sides at the same time, it stays upright.

Return the final state of the row after all dominoes have settled.

Input Format

  • A single string dominoes consisting of L, R, and ..
  • dominoes[i] describes the initial state of the i-th domino.

Output Format

  • Return a string of the same length representing the final state after all forces have propagated.

Constraints

  • 1 <= dominoes.length.
  • The string contains only L, R, and ..
  • The answer is unique.
Examples
Sample cases returned by the problem API.

Example 1

Input

dominoes = ".L.R...LR..L.."

Output

"LL.RR.LLRRLL.."

Explanation

The pushes propagate through the upright dominoes. Some sections fall left, some right, and some remain upright when forces balance.

Example 2

Input

dominoes = "RR.L"

Output

"RR.L"

Explanation

The two right-pushed dominoes do not affect the left-pushed domino because the standing domino between them blocks the forces from meeting in a way that changes the final state.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.