MEDIUMasked at 2 companies

Count Good Nodes in Binary Tree

A medium-tier problem at 73% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at josh technology and 1 others.

Founder's read

You're staring at a binary tree problem where the naive traversal approach feels right until you realize the definition of 'good' nodes changes as you move through the tree. Count Good Nodes in Binary Tree is asked at Docusign and Josh Technology, and it trips up candidates who don't anchor the comparison correctly. The 70% acceptance rate is partly because the pattern is straightforward once you see it, but partly because under pressure, people second-guess whether to track a running max or reset it. If this lands in your OA and you blank on the state you need to carry, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
73%

Companies that ask "Count Good Nodes in Binary Tree"

If this hits your live OA

Count Good Nodes in 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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

A node is 'good' if the value on the path from root to that node is greater than or equal to all previous values on that path. The trick is that you're not comparing nodes to each other; you're tracking the maximum value seen so far on the current root-to-node path. Most candidates either forget to pass the running max through the recursion, or they confuse it with a global max. The solution is a simple DFS, Tree, or BFS traversal where you thread the maximum value seen as you descend. Each time you visit a node, you compare it to that max, increment the count if it qualifies, then update the max and recurse. The problem feels easy once you name the state correctly, but the wording can make you hunt. Under time pressure in a live assessment, StealthCoder is the hedge if you get tangled in the definition and need working code fast.

Pattern tags

The honest play

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

Count Good Nodes in Binary Tree recycles across companies for a reason. It's medium-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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Good Nodes in Binary Tree interview FAQ

Is this problem actually easier than the acceptance rate suggests?+

Yes. The 73% acceptance rate reflects that once you understand the 'good node' definition (value greater than or equal to max on path so far), the code follows naturally. The gap exists because interview pressure makes candidates misinterpret 'on the path' and either compare globally or reset the max incorrectly.

Do I need BFS or is DFS enough?+

DFS is the standard approach and is cleaner for this problem. BFS works too, but you'd need to track the max-on-path alongside each node in the queue, making it more verbose. The problem doesn't penalize either, but DFS is the natural fit.

What's the trap that makes candidates fail this live?+

Forgetting that 'max on path' is specific to the current root-to-node path, not global. Some candidates track a single global max and update it for all nodes, which gives the wrong count. The max must be passed down and updated locally per branch.

Is this still asked at Docusign and Josh Technology?+

Both companies have reported this problem in interviews. The 70% acceptance rate and medium difficulty suggest it's a screening-stage favorite. It's not rare, so it's worth drilling the DFS pattern.

Can I solve this iteratively or must I recurse?+

Both work. Recursive DFS is simpler and matches the tree structure naturally. Iterative DFS with an explicit stack is possible but requires careful state management to track (node, max-on-path) pairs. Go with recursion unless you have a reason not to.

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