PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Uber

Compute sums and maximum path in a tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding and implementation of binary tree traversal, recursion, aggregation of node values, and computation of maximum simple-path sums, measuring competency in data structures and algorithmic problem-solving within the Coding & Algorithms domain.

  • medium
  • Uber
  • Coding & Algorithms
  • Software Engineer

Compute sums and maximum path in a tree

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given a binary tree whose nodes store integer values. You must implement your own `Node` class (e.g., `val`, `left`, `right`). ## Task Write a function that, given the root node, computes all of the following: 1. **Total sum**: the sum of values of **all** nodes in the tree. 2. **Maximum path value**: the maximum possible sum of values along a **simple path** in the tree, where a path: - can start and end at **any** two nodes, - must follow parent-child links, - cannot visit a node more than once. 3. **Nodes on a maximum path**: return one valid path (as a list of node values, or node references) that achieves the maximum path value. ## Input / Output - **Input:** `root` (or `null` for an empty tree). - **Output:** a structure/tuple like `(totalSum, maxPathSum, maxPathNodes)`. ## Constraints (assume) - `0 <= number of nodes <= 2e5` - Node values are integers (may be negative). ## Notes - If the tree is empty, define `totalSum = 0`, `maxPathSum = 0`, and `maxPathNodes = []`. - If multiple maximum paths exist, returning any one is acceptable.

Quick Answer: This question evaluates understanding and implementation of binary tree traversal, recursion, aggregation of node values, and computation of maximum simple-path sums, measuring competency in data structures and algorithmic problem-solving within the Coding & Algorithms domain.

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
Take-home Project
Coding & Algorithms
4
0
Loading...

You are given a binary tree whose nodes store integer values. You must implement your own Node class (e.g., val, left, right).

Task

Write a function that, given the root node, computes all of the following:

  1. Total sum : the sum of values of all nodes in the tree.
  2. Maximum path value : the maximum possible sum of values along a simple path in the tree, where a path:
    • can start and end at any two nodes,
    • must follow parent-child links,
    • cannot visit a node more than once.
  3. Nodes on a maximum path : return one valid path (as a list of node values, or node references) that achieves the maximum path value.

Input / Output

  • Input: root (or null for an empty tree).
  • Output: a structure/tuple like (totalSum, maxPathSum, maxPathNodes) .

Constraints (assume)

  • 0 <= number of nodes <= 2e5
  • Node values are integers (may be negative).

Notes

  • If the tree is empty, define totalSum = 0 , maxPathSum = 0 , and maxPathNodes = [] .
  • If multiple maximum paths exist, returning any one is acceptable.

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.