Maximum Depth of Binary Tree
Reported by candidates from LinkedIn's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
It's all about the binary tree. LinkedIn candidates reported this one in September 2026, and it's Maximum Depth of Binary Tree: return the number of nodes on the longest root-to-leaf path, and 0 for an empty tree. If you've seen trees before, this is a warm-up. If you haven't, it's still short. The trap isn't the idea, it's the 100000 node limit. StealthCoder is there as a safety net on the live OA if your mind goes blank, but you shouldn't need it for this.
The problem
Given the root of a finite binary tree, return its maximum depth: the number of nodes on the longest path from the root to a leaf. Return 0 for an empty tree. Function maximumDepth(root: TreeNode) → int Examples Example 1 root = [3,9,20,null,null,15,7] return = 3 The longest root-to-leaf path contains three nodes. Example 2 root = [] return = 0 An empty tree has depth zero. Constraints The tree contains at most 100000 nodes. Every node value fits in a signed 32-bit integer. The input is a finite acyclic binary tree.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one line of recursion: depth(node) = 0 if null, otherwise 1 + max(depth(left), depth(right)). That's depth-first search, and it's the whole solution. The pitfall is the constraint. A tree with 100000 nodes can be a straight chain, and a recursive solution may blow the call stack in some languages. If that worries you, use an iterative BFS: push the root into a queue, process one level at a time, and count levels. Same O(n) time, and the queue holds at most one level so memory stays bounded. Also handle the empty tree first and return 0. Count nodes, not edges, so example 1 gives 3, not 2. If you blank on the live LinkedIn OA, StealthCoder runs invisibly and gives you the recursive or BFS version to check against.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Maximum Depth of Binary Tree cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as maximum depth of binary tree. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass LinkedIn's OA.
LinkedIn reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Depth of Binary Tree FAQ
How hard is Maximum Depth of Binary Tree really?+
It's easy. The recursive solution is about three lines. LinkedIn reported it in September 2026, so expect a quick one where speed and clean edge cases matter more than cleverness. Don't overthink it or hunt for a hidden twist.
What's the trick to solving it?+
Define depth recursively. An empty node has depth 0. Any other node has depth 1 plus the larger of its two children's depths. Return that from the root. It visits every node once, so time is O(n).
Should I use recursion or BFS?+
Either works. The tree can hold 100000 nodes and could be a single long chain, so recursion risks a stack overflow in some languages. BFS by levels avoids that: count how many levels you process. If you're confident in your language's recursion limit, recursion is shorter.
Do I count nodes or edges?+
Nodes. The problem says the number of nodes on the longest root-to-leaf path. For [3,9,20,null,null,15,7] the answer is 3. An empty tree returns 0, and a single node returns 1.
How do I prepare in 48 hours?+
Write both versions from memory once: recursive DFS and iterative BFS. Test them on an empty tree, a single node, and a long chain. Then do a few related tree problems like balanced tree or diameter, since they reuse the same depth idea.