This theory is part of Premium
The full write-up (worked counting examples, the trap list and the interview playbook) unlocks with a Premium plan, along with every Pro visualizer.
See pricingFind the longest path between any two nodes, counted in edges.
What this asks
Find the longest path between any two nodes, counted in edges.
Return each subtree's height and update a running best with 2 + height(left child) + height(right child) at every node; the best is never returned.
The full write-up (worked counting examples, the trap list and the interview playbook) unlocks with a Premium plan, along with every Pro visualizer.
See pricing