← Back
00:00

House Robber III

Zip interview questions · Medium · Coding round · reported 3× · 6 tests

You are given the root of a binary tree. Each node stores a non-negative integer value.

Select a subset of nodes that maximizes the total sum, with one rule: you may not select both a node and any of its direct children.

Return the largest sum you can obtain.

Function signature

type TreeNode = {
  val: number;
  left?: TreeNode | null;
  right?: TreeNode | null;
};

robTree(root: TreeNode | null): number
Idle