PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/TikTok

Compute maximum path sum in binary tree

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of tree algorithms and recursive reasoning, focusing on aggregation of path metrics and handling of negative node values.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Compute maximum path sum in binary tree

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given the root of a binary tree where each node contains an integer value (which may be negative), return the maximum possible sum of values along any path in the tree. A path is defined as a sequence of nodes where each pair of adjacent nodes in the sequence is connected by a parent-child edge. The path: - Can start and end at any nodes in the tree. - Must contain at least one node. - Cannot jump between branches; it always follows child pointers up or down. For example, in the tree: -10 / \ 9 20 / \ 15 7 The maximum path sum is 42, using the path 15 -> 20 -> 7. Design an algorithm to compute this maximum path sum. Aim for O(n) time, where n is the number of nodes in the tree.

Quick Answer: This question evaluates a candidate's understanding of tree algorithms and recursive reasoning, focusing on aggregation of path metrics and handling of negative node values.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Maximize sum with no adjacent elements - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Find the longest palindromic substring - TikTok (easy)
TikTok logo
TikTok
Nov 16, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
0
0

Given the root of a binary tree where each node contains an integer value (which may be negative), return the maximum possible sum of values along any path in the tree.

A path is defined as a sequence of nodes where each pair of adjacent nodes in the sequence is connected by a parent-child edge. The path:

  • Can start and end at any nodes in the tree.
  • Must contain at least one node.
  • Cannot jump between branches; it always follows child pointers up or down.

For example, in the tree:

-10
/  \

9 20 /
15 7

The maximum path sum is 42, using the path 15 -> 20 -> 7.

Design an algorithm to compute this maximum path sum. Aim for O(n) time, where n is the number of nodes in the tree.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

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