House Robber III (Tree DP)

Medium · Trees · about 25 minutes

Asked at Google, Amazon, Uber.

The houses in a neighborhood form a binary tree; each node holds the money in that house. Robbing two directly-linked houses (parent and child) on the same night triggers the alarm. Given the root, return the maximum amount you can rob.

Related guides