Mid
Trees
DSA & Coding Interviews
How do you find the diameter of a binary tree?
Short answer: Diameter is the longest path between any two nodes (edges count). DFS returns height; at each node update global max of leftHeight + rightHeight. O(n).
Path may not pass through the root — that is the common trap.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png