Loading...

The Level Summer

A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.

Domain
Python
Difficulty
medium
Seniority
junior, mid, senior

Problem

Our org chart analytics tool computes aggregate metrics at each level of the hierarchy. Write a function called level_sums that takes a tree represented as a nested dictionary with 'val' and 'children' keys, and returns a list where element i is the sum of all node values at depth i. The root is depth 0.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.