~/boss / night-owl

Tree DP (rob or skip)

The Night Owl

Rob a house and its neighbours below must be left alone. Solve the tree from the leaves up.

Loading the fight…

How to beat it

Solve the children before their parent. Each house keeps two numbers. ROB: its own gold plus each child's SKIP, because a robbed house's children must be skipped. SKIP: for each child, the better of its two numbers, since a skipped house leaves its children free. A house with no children robs for its gold and skips for 0. At the top, take the better of the root's two numbers.

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/house-robber-iii there. Sign in with your email to keep your progress on every device.

More bosses

esc