Opening your workspace…
Workspace/Coding room
Opening your workspace…
The brewery stores ingredients on a branching shelf system. A leaf is a shelf with no children. Return the sum of stock[i] only at leaf shelves; stock on internal shelves does not count. A single shelf is itself a leaf. 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], [50,20,4,7]OUTPUT11Shelves 2 and 3 have no children, so only their 4 + 7 units count.
[-1], [9]OUTPUT9The only shelf has no children and is therefore a leaf.
Tab inserts two spaces. Press Escape, then Tab, to leave the editor. Press Control or Command and Enter to submit.
[-1,0,0,1], [50,20,4,7]11Public 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…