PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Compute sums and max path in N-ary tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates implementation and traversal skills for N-ary tree data structures, including recursion/DFS techniques, aggregation of node values, and tracking root-to-leaf path sums.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Compute sums and max path in N-ary tree

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given the root of an **N-ary tree** (each node can have 0..k children). Implement the `Node` class yourself. Assume each node stores an integer `value` and a list of child nodes `children`. Complete the following tasks: 1. **Sum of all nodes**: Return the sum of `value` over **all** nodes in the tree. 2. **Maximum path value**: Define a *path* as a sequence of nodes from the **root to any leaf** (a node with no children). The *path value* is the sum of node values along that path. Return the **maximum** root-to-leaf path value. 3. **Return the max path**: Return the list of node values along one root-to-leaf path that achieves the maximum path value from (2). If multiple paths tie, you may return any one of them. ### Input / Output - Input: `root: Node | null` - Output: - (1) an integer total sum - (2) an integer maximum root-to-leaf path sum - (3) an array/list of integers representing the values along the chosen max path ### Notes / Constraints - The tree can be empty (`root = null`). - Node values can be negative, zero, or positive. - Aim for linear time in the number of nodes.

Quick Answer: This question evaluates implementation and traversal skills for N-ary tree data structures, including recursion/DFS techniques, aggregation of node values, and tracking root-to-leaf path sums.

Related Interview Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)
Uber logo
Uber
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

You are given the root of an N-ary tree (each node can have 0..k children). Implement the Node class yourself.

Assume each node stores an integer value and a list of child nodes children.

Complete the following tasks:

  1. Sum of all nodes : Return the sum of value over all nodes in the tree.
  2. Maximum path value : Define a path as a sequence of nodes from the root to any leaf (a node with no children). The path value is the sum of node values along that path. Return the maximum root-to-leaf path value.
  3. Return the max path : Return the list of node values along one root-to-leaf path that achieves the maximum path value from (2). If multiple paths tie, you may return any one of them.

Input / Output

  • Input: root: Node | null
  • Output:
    • (1) an integer total sum
    • (2) an integer maximum root-to-leaf path sum
    • (3) an array/list of integers representing the values along the chosen max path

Notes / Constraints

  • The tree can be empty ( root = null ).
  • Node values can be negative, zero, or positive.
  • Aim for linear time in the number of nodes.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Uber•More Software Engineer•Uber Software Engineer•Uber Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ 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.