As reported: Qualcomm Engineer (C++), technical round 1 (2025): find the maximum element in a binary tree, then a follow-up similar to Binary Tree Maximum Path Sum; both were solved in about 30 minutes.
Warm-up: the maximum element of a binary tree is one traversal comparing every node.
The main problem: a path is a sequence of nodes where each adjacent pair is connected by an edge; a node appears at most once, and the path need not pass through the root. Its sum is the sum of its node values. Given the root, return the maximum path sum over all non-empty paths.
This is LeetCode 124 — Binary Tree Maximum Path Sum.
Example 1
root = [1,2,3] -> 6 (2 -> 1 -> 3)
Example 2
root = [-10,9,20,null,null,15,7] -> 42 (15 -> 20 -> 7)
Constraints: 1 ≤ nodes ≤ 3·10^4; -1000 ≤ Node.val ≤ 1000.
Code runner format: one line, the tree in LeetCode's level-order format. Implement maxPathSum(root); the harness prints the sum.