graph TD
A[10]
A --> B[8]
A --> C[2]
B --> D[3]
B --> E[5]
C --> F[2]
C --> G[1]
classDef maxPath fill:#f9f,stroke:#333,stroke-width:2px;
A:::maxPath
B:::maxPath
E:::maxPath
1
2
3
Input: [10,8,2,3,5,2,1]Output: [10,8,5]Explanation: The maximum sum path from root to leaf is10->8->5 which has a sum of 23.
graph TD
A[-10]
A --> B[20]
A --> C[30]
B --> D[-10]
B --> E[50]
C --> F[35]
C --> G[100]
classDef maxPath fill:#f9f,stroke:#333,stroke-width:2px;
A:::maxPath
C:::maxPath
G:::maxPath
1
2
3
Input: [-10,20,30,-10,50,35,100]Output: [-10,30,100]Explanation: The maximum sum path from root to leaf is-10->30->100 which has a sum of 120.
To find the maximum sum root-to-leaf path in a binary tree, we need to explore all paths from leaves to the root. This involves traversing the tree and at each node, keeping track of the maximum sum path rooted at that node.