Z30

House Robber III (Tree)

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

Problem Statement & Objective

The thief has found himself a new place for his thievery again: a binary tree where houses are connected like tree nodes. No two directly-linked houses can be broken into.

Function Signature (Python)

house_robber_iii_tree(root: list) -> int

Input & Output Contract

Output Rule:Maksimum para miktarı.

System Constraints

0 <= agac.length <= 10^4
0 <= agac[i] <= 10^4

Example Execution Walkthrough

agac = [3, 2, 3, None, 3, None, 1]
3 (kök) + 3 + 1 = 7 (en iyi)
cevap: 7

Example Test Scenarios (3)

Example 1
Input:[[3,2,3,null,3,null,1]]
Expected Output:7
Example 2: 4 + 5 = 9
Input:[[3,4,5,1,3,null,1]]
Expected Output:9
Example 3: Boş
Input:[[]]
Expected Output:0
Loading Python Editor...
Input Parameters
[
  [
    3,
    2,
    3,
    null,
    3,
    null,
    1
  ]
]
Expected Output
7