Settle a Row of Pushed Dominoes Into Its Final State

Last updated: November 29, 2026

Quick Overview

A row of dominoes is described by a string of 'L', 'R', and '.', where L and R are dominoes pushed at time 0. Each second a falling domino pushes its neighbor in the same direction, and a domino pushed from both sides at once stays upright; return the final row.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


A row of dominoes is described by a string of 'L', 'R', and '.', where L and R are dominoes pushed at time 0. Each second a falling domino pushes its neighbor in the same direction, and a domino pushed from both sides at once stays upright; return the final row.

A Google phone screen problem that rewards turning a time-step simulation into a single pass. Interviewers look for either the force accumulation trick or segment analysis between pushed dominoes, plus correct handling of the balanced middle.

What the Interviewer Expects
  • Show the naive tick simulation and why it can be O(n^2)
  • Analyze segments between consecutive pushed dominoes
  • Handle R...L by filling from both ends and leaving the middle upright on odd length
  • Handle L...L, R...R, and L...R segments
  • Run in O(n)
Key Topics to Cover
simulation
two pointers
string processing
forces
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the time each domino falls, not just its direction.
  • What if dominoes have different heights that knock over more than one neighbor?
  • How would you process this on a stream that arrives in chunks?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: string s over L, R, .. A domino falling left pushes the one on its left one second later, likewise for right. Already falling dominoes do not change. Output a string of the same length....

High-Level Design

Pad the string with a virtual L on the left and R on the right. Then walk pairs of consecutive non-dot characters a at index i and b at index j:

  • a == b: everything between falls that way....

Submit Your Answer
Markdown supported