Medium data structure and algorithm practice puzzle.
Given a distribution tree where a node holds 1 when it has a subscriber and 0 when it does not, return how many nodes stay after pruning. A node stays if it subscribes, or if anything beneath it does, because it still has to forward. This is post-order work: a parent cannot decide until its children have reported, which is the shape of every 'compute something about the subtree' problem and the reason multicast prunes from the leaves upward.
Solve it three ways: snap the jigsaw pieces together, fill in the blanks, or type it from scratch against the tests. This one is free.
Browse all 536 puzzles