Medium data structure and algorithm practice puzzle.
Given a hierarchy of resource groups where each node declares a limit, and a path down from the root, return the limit that actually applies at the end of it, or -1 when the path does not exist. A child cannot grant itself more than its parent allows, so the effective limit is the smallest declaration anywhere on the path. This is the one tree walk that carries information DOWN rather than combining answers on the way back up, and it is how every nested budget behaves, from cgroups to disk quotas.
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