# stacks advanced

Knock Down the Smaller Towers

Each new tower rolls in from the right and flattens every SHORTER tower in its path, stopping at the first one as tall or taller. 🏗️

You get the tower heights in arrival order. Simulate the destruction and print the surviving towers left to right, comma-separated.

Example:

Input: heights = [3, 1, 4, 2, 5] Output: 5

1 isn't flattened by anything yet, but 4 rolls in and flattens both 3 and 1; 2 survives behind 4; then 5 rolls in and flattens 4 and 2 — only 5 survives.

💡 need a hint?

stk-knock-down-towers.py🔒 given lines are locked — write your code in between
loading...