All problems
1056MediumTwo PointersStringDynamic Programming

Where the Pushed Tiles Settle

Tracked in this browser only
Write code

Trains the technique from

LeetCode 838Push Dominoes

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def push_dominoes(tiles: str) -> str:
Java
public String pushDominoes(String tiles)
September 7
Apply