Find Maximum Path Sum in N-ary Tree
Company: Nuro
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of tree traversal and aggregation techniques, including handling of variable-arity nodes, negative values, and path-based dynamic programming on N-ary trees.
Constraints
- Tree is non-empty
Examples
Input: ([1, [[2, []], [3, [[5, []], [-6, []]]], [4, []]]],)
Expected Output: 13
Explanation: Prompt-style tree.
Input: ([-5, []],)
Expected Output: -5
Explanation: Single negative node.
Input: ([0, [[-1, []], [-2, []]]],)
Expected Output: 0
Explanation: Best can be single root.
Hints
- At each node, combine the top two nonnegative child gains for a path through that node.