Opening your workspace…
Workspace/Coding room
Opening your workspace…
A brewery lift visits every tier of a branching storage tree. The root is at depth 0; each parent-child link increases depth by 1. Return the sum of trays[i] at each depth, from depth 0 through the deepest occupied depth. Include tiers whose sum is zero. The tree has nodes numbered 0 through n - 1. parent[0] is -1; every other parent[i] is the parent of node i. The tree is connected and has no cycles. Node numbers do not imply traversal order: a parent may have a larger number than its child.
[-1,0,0,1], [2,3,5,7]OUTPUT[2,8,7]The root holds 2 trays; nodes 1 and 2 share tier 1 with 8 trays; node 3 supplies tier 2 with 7.
[-1], [0]OUTPUT[0]The root tier exists even when it has no trays.
Tab inserts two spaces. Press Escape, then Tab, to leave the editor. Press Control or Command and Enter to submit.
[-1,0,0,1], [2,3,5,7][2,8,7]Public samples only. These checks do not award ranked points.
Walk through a solution, check its time and space costs, and compare it with yours.
Checking your progress…