BackmediumTree Data Structures tree-data-structures medium

Maximum Root Leaf Path Sum Solution

Problem Statement

Given a tree where each node has a value and a list of its child nodes, find the maximum sum of node values from the root node to a leaf node. The tree is represented as a nested list, where each node is a list containing the node's value and a list of its child nodes.

Example 1
Input
[[1, [[2], [[3], [4]]]]]
Output
6

Explanation: The path with the maximum sum is 1 -> 2 -> 3, resulting in a sum of 6.

Constraints

  • The number of nodes in the tree will not exceed 1000.
  • The value of each node will be in the range [-10^4, 10^4].
  • The tree will not be empty.
  • Each node will have at most 10 child nodes.
  • The depth of the tree will not exceed 1000.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free