O08

Tree Layer Sums

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

Compute the sum of node values at each depth level in a binary tree from root to leaf.

Function Signature (Python)

tree_layer_sums(arr: list) -> list[int]

Input & Output Contract

Output Rule:Katman toplamları dizisi. Boş dizi girdisi için boş dizi [].

System Constraints

0 <= dizi.length <= 10^5
düğüm değerleri -10^4 .. 10^4 (NEGATİF OLABİLİR)

Example Execution Walkthrough

dizi = [1, 2, 3, 4, 5, 6, 7]
katman 0: [1] -> 1
katman 1: [2, 3] -> 5
katman 2: [4, 5, 6, 7] -> 22
cevap: [1, 5, 22]

Example Test Scenarios (3)

Example 1
Input:[[1,2,3,4,5,6,7]]
Expected Output:[1,5,22]
Example 2: İki Katmanlı Ağaç
Input:[[1,2,3]]
Expected Output:[1,5]
Example 3: Tek Kök Düğüm
Input:[[10]]
Expected Output:[10]
Loading Python Editor...
Input Parameters
[
  [
    1,
    2,
    3,
    4,
    5,
    6,
    7
  ]
]
Expected Output
[
  1,
  5,
  22
]