Push Dominoes - Problem
Imagine you're looking at a line of n dominoes standing upright. Suddenly, some dominoes are pushed - some topple to the left (L), others to the right (R), while some remain upright (.).
Physics takes over! Each second, falling dominoes push their neighbors in the same direction. When a domino gets pushed from both sides with equal force, it stays perfectly balanced and upright.
Your mission: Given the initial state as a string where
Example:
Physics takes over! Each second, falling dominoes push their neighbors in the same direction. When a domino gets pushed from both sides with equal force, it stays perfectly balanced and upright.
Your mission: Given the initial state as a string where
'L' means pushed left, 'R' means pushed right, and '.' means upright, determine what the dominoes look like after they've all settled.Example:
"R.L" becomes "RRL" - the middle domino gets pushed right before the left force reaches it! Input & Output
example_1.py — Basic Example
$
Input:
dominoes = "RR.L"
›
Output:
"RRRL"
💡 Note:
The first domino is already falling right, the second is already falling right, the third gets pushed right by the second domino (force arrives at t=1) before being affected by the fourth domino's leftward force, and the fourth is already falling left.
example_2.py — Balanced Forces
$
Input:
dominoes = ".L.R...LR..L.."
›
Output:
"LL.RR.LLRRLL.."
💡 Note:
Multiple force interactions create various regions where dominoes fall left, right, or remain upright when forces balance.
example_3.py — No Forces
$
Input:
dominoes = "..."
›
Output:
"..."
💡 Note:
When no dominoes are initially pushed, they all remain upright.
Constraints
- 1 ≤ dominoes.length ≤ 105
-
dominoes[i] is either
'L','R', or'.' - All dominoes fall at the same speed (1 position per second)
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code