← Tree Recursion

Pattern Recognition Drill

#90 — Diameter of binary tree

Easy Advanced Trees

The Problem

Find the diameter (longest path between any two nodes).

What approach would you use?

Think about it before scrolling down.

Key Signals

Tree Recursion

Height recursion, update global max = left_h + right_h at each node. O(n).

Common Trap

The diameter doesn't necessarily pass through the root! Must check at every node.

← #89 #91 →