FastPrepBinary Tree Maximum Path Sum
Problems/Binary Tree Maximum Path Sum

Binary Tree Maximum Path Sum

JP Morgan Chase logoJP Morgan Chase● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase new grad onsite interview. The report asks for the largest path sum from any node to any node in a binary tree. We chose the rule that a path is not empty, the tree limits and the function interface. Our version is about 90% the same as the reported question.

Return the greatest sum of a path in a binary tree. A path follows parent-child edges, may start and end at any nodes, and cannot visit a node more than once.

For this exercise, assume the tree and the chosen path are nonempty. A path may contain just one node, and it does not have to pass through the root.

Function

maxPathSum(root: TreeNode) → int

Examples

Example 1

root = [1,2,3]return = 6
root
123

The path 2 → 1 → 3 has sum 6.

Example 2

root = [-10,9,20,null,null,15,7]return = 42
root
-10920157

The path 15 → 20 → 7 has sum 42. It stays below the root.

Example 3

root = [-3]return = -3
root
-3

The only nonempty path contains the single node with value -3.

Constraints

  • 1 <= number of level-order entries <= 599, including null markers.
  • -1000 <= node value <= 1000
  • The input is a nonempty binary tree in valid level-order form with trailing null markers omitted.

More JP Morgan Chase Onsite Interview questions

  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
  • Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
  • K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
  • Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
  • Two SumONSITE INTERVIEW · Seen Nov 2025
  • Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
  • Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
  • Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024

Similar questions at other companies

  • Sum of Weighted Distances in a TreeGoogle · ONSITE INTERVIEWGoogle interview questions
  • File Encryption Tree OptimizationDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Binary Tree Maximum Path SumGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Binary Tree Maximum Path SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Binary Tree Maximum Path SumGlobalization Partners · ONSITE INTERVIEW
  • Binary Tree Maximum Path SumByteDance · ONSITE INTERVIEWByteDance interview questions
  • Transitive Employee Referral CountsRobinhood · ONSITE INTERVIEWRobinhood interview questions
  • Maximum Nonadjacent Sum in a General TreeZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
  • Maximum Sum of Non-Adjacent Tree NodesInMobi · ONSITE INTERVIEWInMobi interview questions
  • Distance Sums to Special Nodes in a Weighted TreeNutanix · ONSITE INTERVIEWNutanix interview questions

Interview reports that mention this question

  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
  • JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int maxPathSum(TreeNode root) {
        // Write your code here.
    }
}
Checking account…