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
- L3
Problem
You're rolling a metric up a category tree whose nodes each carry an integer `val` and a list of `children` nodes, where that list may be empty. Return a list whose entry at index i is the combined `val` of every node at depth i, counting the root as depth 0 so that even a leaf still contributes to the total at its own depth.
Summary
Every tier of the hierarchy keeps its own total.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.