Idea behind the solution The idea here is to remove the leafs while its value is 0. By doing a DFS, we are able to reach the leaf first and return removing it if needed.