Dashboard
LC #124
Binary Tree Maximum Path Sum
Pattern · ?AmazonGoogleMetaBloomberg
Problem
Find the maximum path sum where the path can start and end at any node.
Constraints
- 1 ≤ n ≤ 3 × 10⁴
- -1000 ≤ Node.val ≤ 1000
- Path can start and end at any node; must contain at least one node
Example
- Input
- root = [-10, 9, 20, null, null, 15, 7]
- Output
- 42
- Why
- Optimal path: 15 → 20 → 7 = 42 (does not have to pass through root)
Spot the pattern
Which pattern cracks it?
Hints
One at a time