Push Dominoes
Real-world version: Where the Pushed Tiles SettleThe statement here is our own: the same inputs, outputs and technique.
A row of tiles stands on edge and reads tiles. Each character is 'L' for a tile pushed leftwards at the same instant, 'R' for one pushed rightwards, and '.' for one left standing.
A falling tile pushes the standing tile beside it in the same direction, which then falls too, and so on. A standing tile pushed from both sides at the same instant stays standing. A tile already fallen is unaffected by anything that reaches it later.
Return the row once everything has settled.
Examples
Example 1
- Input
- tiles = "..R.."
- Output
- "..RRR"
The pushed tile topples everything to its right, one after another. The two standing tiles to its left have nothing pushing them at all.
Example 2
- Input
- tiles = "R.L"
- Output
- "R.L"
The middle tile is reached from both sides at the same instant, so it stays standing.
Example 3
- Input
- tiles = "L..R.."
- Output
- "L..RRR"
The leftward push at the front has nothing behind it to topple. The two standing tiles between the pushes are pushed apart rather than together, so neither falls. The rightward push topples everything after it.
Constraints
- 1 <= tiles.length <= 10^5
- Every character of tiles is 'L', 'R' or '.'.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def push_dominoes(tiles: str) -> str:public String pushDominoes(String tiles)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Is SubsequenceReal-world version: Shorthand Fits the LabelEasy
- Longest Palindromic SubstringReal-world version: Longest Mirror RunMedium
- Palindromic SubstringsReal-world version: Reversible Tape StretchesMedium
- Find the Lexicographically Smallest Valid SequenceReal-world version: Cheapest Probe Slots On A ReelMedium