Leetcode 1443: Minimum Time to Collect All Apples in a Tree

In this Leetcode problem, we are to return the minimum number of steps to pickup all the apples in an undirected tree, starting from the node 0.

Problem statement

Here is the draft of ideas to solve the problem recursively:

  • Let’s call visit(p) the cost to visit the subtree with root p. For instance, in the above…