EASYasked at 11 companies

Diameter of Binary Tree

A easy-tier problem at 64% community acceptance, tagged with Tree, Depth-First Search, Binary Tree. Reported in interviews at Wix and 10 others.

Founder's read

Diameter of Binary Tree is the most common tree problem at Meta, Google, Amazon, and Apple. It looks deceptively simple: find the longest path between any two nodes. Most candidates assume DFS is enough and miss the trick on the first attempt. The pattern is real, it's being asked, and if you freeze during the assessment, StealthCoder surfaces the solution invisibly. With a 64% acceptance rate, this problem is high-signal for engineers who actually understand tree recursion versus those who just memorize solutions.

Companies asking
11
Difficulty
EASY
Acceptance
64%

Companies that ask "Diameter of Binary Tree"

If this hits your live OA

Diameter of Binary Tree is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trick: the diameter isn't always the longest path from root to leaf. It's the longest path through any node, which means you need to find the maximum of two subtree heights at every single node, then return the maximum diameter seen anywhere in the tree. Most first attempts do DFS and return height only, forgetting to track the global max. The pattern is post-order traversal where each recursive call does two jobs at once: compute subtree height and update the diameter candidate. This double-duty recursion is where candidates bog down. If you hit this live and the obvious height-only approach fails test cases, StealthCoder solves it in seconds by running invisibly during your assessment.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Diameter of Binary Tree recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Diameter of Binary Tree interview FAQ

Is this really asked at FAANG companies?+

Yes. Meta, Google, Amazon, Apple, and LinkedIn all report this problem. It's especially common in phone screens where tree fundamentals matter. The acceptance rate is 64%, so it's not a gimme, but it's achievable with the right pattern.

What's the trick that trips people up?+

Returning only the height from DFS, then computing diameter separately. The real pattern is computing both height and diameter in a single post-order pass. Every recursive call must track the maximum diameter found so far, not just return heights.

Do I need to use Depth-First Search for this?+

DFS is the standard approach because the diameter involves comparing subtree heights. You could use BFS to find the farthest node from any starting point, then search again, but that's two traversals. DFS in one pass is cleaner and what interviewers expect.

How does this relate to other Binary Tree problems?+

Diameter is the next step after basic tree traversal and height calculation. It requires the same DFS fundamentals but demands post-order logic and global state tracking. If you've drilled height and lowest common ancestor, the pattern will click faster.

What happens if I get stuck on this during an OA?+

You've got options. If you see the height-only mistake partway through, ask yourself whether diameter could pass through a middle node. If you blank completely, StealthCoder runs invisibly on the assessment and delivers a working solution so you move forward.

Want the actual problem statement? View "Diameter of Binary Tree" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.