EASYasked at 1 company

Count Complete Tree Nodes

A easy-tier problem at 70% community acceptance, tagged with Binary Search, Bit Manipulation, Tree. Reported in interviews at Dunzo and 0 others.

Founder's read

Count Complete Tree Nodes is a deceptively simple problem that catches candidates who code the obvious solution first. Given a complete binary tree, you need to return the total number of nodes. The naive approach is O(n): walk every node and count. But a complete tree has structure you can exploit. Dunzo has asked this. The trick separates people who understand tree properties from those who just traverse. Your live OA timer won't be kind to the brute force if the tree is massive. StealthCoder catches you if the insight doesn't click in real time.

Companies asking
1
Difficulty
EASY
Acceptance
70%

Companies that ask "Count Complete Tree Nodes"

If this hits your live OA

Count Complete Tree Nodes 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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.

Get StealthCoder
What this means

The insight: a complete tree's structure means you can find the answer in O(log n * log n) time using binary search on depth and bit manipulation to navigate the tree without walking every node. Count the left and right subtree heights. If they're equal, the left subtree is perfectly full; if not, the right subtree is. Recurse on the full side first. Most candidates miss this and implement DFS or BFS, which works but eats time on large inputs and looks naive in the interview. The pattern doesn't generalize to arbitrary binary trees, which is why depth-checking and height-comparison matter here. If you blank on the optimization mid-OA, StealthCoder surfaces the binary search solution instantly while the proctor sees nothing.

Pattern tags

The honest play

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

Count Complete Tree Nodes 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. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Complete Tree Nodes interview FAQ

What makes this 'Easy' when the optimal solution is O(log n * log n)?+

LeetCode tags 'Easy' based on acceptance rate, not true difficulty. At ~70% pass rate, people solve it with DFS and move on. The optimal binary search solution is harder but unnecessary to pass. Know both paths: brute force works, but optimization is the real interview signal.

Is the naive O(n) traversal actually wrong?+

Not wrong, just inefficient. It passes test cases but shows you didn't recognize the complete tree property. Interviewers ask follow-ups: 'Can you do better?' If you're stuck there during the live assessment, you need the binary search pattern fast.

How do bit manipulation and binary search connect here?+

Binary search narrows down which subtree is full by comparing left and right heights. Bit manipulation helps compute tree indices and navigate paths in O(log n) steps per recursion level. They work together to avoid traversing all n nodes.

Does this problem actually show up in real OAs?+

Rarely at scale, but Dunzo reported it. It's a classic tree interview problem that tests whether you optimize or just iterate. If you see it in a real assessment and the obvious solution comes to mind first, you're on the right track. Optimization is a bonus.

What's the most common mistake during the live assessment?+

Overcomplicating the recursion or forgetting to check whether a subtree is perfectly full. Candidates often implement DFS, run out of time explaining it, then realize there's a faster path but can't pivot. StealthCoder solves this wall in seconds, invisible to the proctor.

Want the actual problem statement? View "Count Complete Tree Nodes" 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.