This question evaluates understanding and implementation of binary tree traversal, recursion, aggregation of node values, and computation of maximum simple-path sums, measuring competency in data structures and algorithmic problem-solving within the Coding & Algorithms domain.
You are given a binary tree whose nodes store integer values. You must implement your own Node class (e.g., val, left, right).
Write a function that, given the root node, computes all of the following:
root
(or
null
for an empty tree).
(totalSum, maxPathSum, maxPathNodes)
.
0 <= number of nodes <= 2e5
totalSum = 0
,
maxPathSum = 0
, and
maxPathNodes = []
.