Company: Razorpay_4sep
Difficulty: medium
Optimal Candy Collection Problem Description You're given a tree with N nodes and N - 1 edges, rooted at node 1, and every node holds exactly one candy. The candy sitting at the i th node costs A i . You start with K units of money and must pick exactly one node, call it u, then buy candies moving upward: first the candy at u itself, then the candy at u's parent, then that node's parent, and so on toward the root, stopping the moment you can no longer afford the next candy or you have already bought the one at the root. You are not allowed to skip a node on this upward path and buy a later one instead. Work out, over all possible choices of starting node u, the largest number of candies you can end up buying with your K units of money. Notes A graph is connected if, for each pair of nodes u and v, there exists a path between these two nodes in the graph. A tree is a connected graph with N nodes and N - 1 edges. Function description Complete the solve function. This function takes the f