PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • hard
  • Nuro
  • Coding & Algorithms
  • Machine Learning Engineer

Find Maximum Path Sum in N-ary Tree

Company: Nuro

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given the root of an N-ary tree. Each node contains an integer value and a list of zero or more children. A path is a sequence of nodes where each adjacent pair is connected by an edge. The path may start and end at any two nodes in the tree, but it must not visit any node more than once. Return the maximum possible sum of node values along any path in the tree. Example: ```text 1 / | \ 2 3 4 / \ 5 -6 ``` One maximum-sum path is `5 -> 3 -> 1 -> 4`, with sum `13`. Constraints: - The tree contains at least one node. - Node values may be positive, zero, or negative. - Each node may have any number of children.

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.

Return the maximum sum over any simple path in an N-ary tree encoded as [value, children].

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

  1. At each node, combine the top two nonnegative child gains for a path through that node.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Parse logs and count error codes - Nuro (easy)
  • Group points by distance threshold - Nuro (medium)
  • Find gaps between intervals - Nuro (medium)
  • Implement BFS and a Job Scheduler - Nuro (hard)