Sum Each Tree Level
Add up the values on each level of a tree, from the top level down.
The problem
Implement tree_level_sums(values, children, root). The tree's nodes are numbered from 0: values[i] is the value of node i, and children[i] lists the indices of node i's children from left to right. Starting at node root, return a list with the sum of the values on each level, from the root's level down. When the tree is empty, root is -1; return [] in that case.
Starter code
def tree_level_sums(values, children, root):
passPublic examples
values = [5, 2, 7, 1, 3], children = [[1, 2], [3, 4], [], [], []], root = 0gives[5, 9, 4]values = [8], children = [[]], root = 0gives[8]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
