Loading...
Loading...
Loading...
A route follows parent-child links and may start and end at any nodes, but it cannot visit a node twice. Print the largest possible sum of values on one route. The route has at least one node.
Example 1
Input
-10 9 20 null null 15 7
Output
42
The route 15, 20, 7 adds up to 42.
Example 2
Input
-3
Output
-3
Try the problem first. Open one hint at a time.
Compute the best gain going down from each node, ignoring a negative gain.
A route that bends at a node adds both gains to its value.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor