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.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details