Opening your workspace…
Workspace/Coding room
Opening your workspace…
Each shelf stores stock[i] units. A branch rooted at a shelf contains that shelf and all of its descendants. Count how many branch totals are between lower and upper, inclusive. Count every qualifying root separately even when its branch overlaps another qualifying branch. 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], 7, 10OUTPUT2Branch 1 holds 3 + 7 = 10 and branch 3 holds 7. The other totals, 17 and 5, are outside the band.
[-1,0,1], [0,0,0], 0, 0OUTPUT3All three overlapping branches total zero, so all three roots qualify.
A branch total is its own stock plus its child branch totals. Make sure children are finished before their parents.
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], 7, 102Public samples only. These checks do not award ranked points.