MEDIUMasked at 2 companies

Count Nodes With the Highest Score

A medium-tier problem at 51% community acceptance, tagged with Array, Tree, Depth-First Search. Reported in interviews at Visa and 1 others.

Founder's read

Count Nodes With the Highest Score is a medium-difficulty tree problem that's been asked at Visa and DoorDash. You're given a binary tree and need to compute a "score" for each node based on the product of subtree sizes, then count how many nodes tie for the highest score. The 51% acceptance rate tells you it's not a one-liner. Most candidates mess up the tree traversal order or the product calculation itself. If this problem hits your live assessment and you freeze on the scoring logic, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
51%

Companies that ask "Count Nodes With the Highest Score"

If this hits your live OA

Count Nodes With the Highest Score 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 core trick: you need two passes or a single DFS that computes subtree sizes bottom-up while calculating scores. For each node, the score is the product of its left subtree size, right subtree size, and the size of everything above it (total nodes minus current subtree). The pitfall is getting the "above" calculation wrong, or computing it top-down when you should go bottom-up. Many candidates also miss that the product can overflow or that you need to handle the root node differently (no parent contribution). A depth-first search with proper bookkeeping solves this, but the implementation details are where people slip. When you hit this live and the recursion logic starts tangling, StealthCoder handles the tree traversal and scoring for you, no proctor visibility.

Pattern tags

The honest play

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

Count Nodes With the Highest Score 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. 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.

Count Nodes With the Highest Score interview FAQ

What's the actual trick to this problem?+

You need to compute a score for each node as the product of left subtree size, right subtree size, and the nodes outside that subtree. The outside nodes are total nodes minus the current subtree size. This requires either two passes or careful DFS bookkeeping to track both subtree sizes and the accumulated product. Most solutions use a single DFS with memoization or a post-order traversal.

Why is the acceptance rate only 51%?+

Candidates often get the score calculation partially right but mess up the "outside" component. Others compute subtree sizes correctly but fail to properly multiply them together or forget edge cases like single-node trees. The problem also requires careful handling of root nodes, which have no parent contribution.

Is this problem still asked at FAANG-adjacent companies?+

It's confirmed at Visa and DoorDash. These are strong, actively interviewing companies, so yes, this pattern is still live in their hiring loops. Medium difficulty and binary tree fundamentals make it a solid mid-level screening question for backend and systems roles.

How does this relate to other tree problems?+

It combines depth-first search and subtree size calculation, which appear in many tree problems. However, the product-based scoring and the need to compute node contributions from outside the subtree make it more complex than basic DFS or size queries. It sits at the boundary between recursion understanding and graph traversal strategy.

What's the time and space complexity?+

Time is O(n) because you visit each node once in the DFS. Space is O(h) for the recursion stack, where h is tree height (or O(n) in the worst case of a skewed tree). No extra data structure is required if you're careful with your DFS bookkeeping, though some solutions use a hashmap to store subtree sizes for clarity.

Want the actual problem statement? View "Count Nodes With the Highest Score" 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.