~/boss / castle-floors

Level order traversal (BFS with a queue)

The Castle Floors

Clear the castle one whole floor at a time. Only the front of the queue moves.

Loading the fight…

How to beat it

Start with the top room in a queue. Take the room at the front, visit it, and push its children to the back, left then right. At the start of each floor, note the queue's size: that's exactly how many rooms the floor has.

Now the real boss

Interviews ask for the code. Watch it run, then write it yourself, tested in Python, C++ or Java.

On your phone? Writing code is easier on a laptop: open bossfight.dev/problems/binary-tree-level-order-traversal there. Sign in with your email to keep your progress on every device.

More bosses

esc