The question clearly asks to output the path with the highest sum, and defines the path as having at least 2 nodes.
The given solution outputs the maximum sum, not the path.
Keeping track of the max path and constructing it in the correct order is a significant part of the challenge of this question, which the solution ignores.
It also ignores negatives, which is wrong. If the whole tree is negative numbers, there’s still a valid path of at least 2 nodes that equates to the maximum sum.
The correct output should be:
Maximum Path Sum: [2,1,3]
Maximum Path Sum: [8,5,3,6,9]
Maximum Path Sum: [-3,-1]