Loading...
Loading...
Loading...
A route goes downward from a node to one of its descendants, starting and ending at any nodes. Print how many such routes add up to the target. A single node counts as a route.
Example 1
Input
10 5 -3 3 2 null 11 3 -2 null 1 8
Output
3
The routes are 5 + 3, 5 + 2 + 1 and -3 + 11.
Example 2
Input
1 1
Output
1
Try the problem first. Open one hint at a time.
Keep the sums along the current route from the root.
A route ending here starts after an earlier sum equal to (current sum - target).
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor