Company: MediaNet_8oct
Difficulty: medium
Fruits on Tree Problem Description You are given a complete rooted tree with N nodes numbered 1 to N. Picture this tree upside down, with its leaves up top and its root down at the bottom; being complete means every leaf sits at the same depth. Each leaf starts out holding some fruit, and collecting all of it means shaking the tree some number of times. This particular tree behaves a bit differently from an ordinary one: Every node has a capacity value describing the most fruit it can hold at any given moment. A single shake moves exactly one fruit from each node down into its parent node. Whenever a node ends up holding more fruit than its capacity right after a shake, the surplus (whatever is above capacity) immediately spills onto the ground — no extra shake is needed for that to happen. The tree's root is node 1, and you can treat the root as sitting just one level above the ground, so anything that falls out of the root lands directly on the ground. Determine the fewest shakes nee