Levels Sum

BINARY TREE

Problem

Given the root of a binary tree, return an array where each element represents the sum of the values of the nodes at that depth (depth is the number of edges from the root to the node).

Examples

sumAtTreeDepths([1,4,2,null,null,3,5]) // returns [1, 6, 8] // Depths: // - 0: 1 (sole root node). // - 1: 4 + 2 = 6. // - 2: 3 + 5 = 8.
Loading...
1
4
2
5
3