AlgoFrames

Fill the two numbers

Warm-up · Trace the algorithm · about 6 min

Follow house robber on a four-house tree. Each house shows two numbers: the best total if it is robbed, then the best if it is skipped. Answer each question before the step plays.

Example 1

Input:

{"levelOrder":[2,1,3,null,4]}

Output:

7

Constraints

  • The trace uses the tree shown.
  • Two houses joined by an edge cannot both be robbed.

Learn the idea first: Tree DP, a visual lesson.

More Tree DP problems