Loading...
Loading...
Loading...
Each node holds an amount. A route starts at the top node and ends at a node with no children. Print YES if some route adds up to exactly the target, and NO if none does.
Example 1
Input
5 4 8 11 null 13 4 7 2 null null null 1 22
Output
YES
The route 5, 4, 11, 2 adds up to 22.
Example 2
Input
1 2 3 5
Output
NO
The routes add up to 3 and 4.
Try the problem first. Open one hint at a time.
Subtract each node's value from the target while going down.
Test for zero only at a node with no children.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor