MEDIUMasked at 1 company

Sum of Nodes with Even-Valued Grandparent

A medium-tier problem at 86% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at Salesforce and 0 others.

Founder's read

Sum of Nodes with Even-Valued Grandparent is a medium-difficulty tree traversal problem with an 85% acceptance rate, meaning most candidates who attempt it pass. Salesforce has asked it. The premise is straightforward: traverse a binary tree, identify nodes whose grandparent has an even value, and sum them. The catch is that grandparent logic forces you to track context as you traverse, not just process nodes in isolation. If you blank on how to pass parent and grandparent pointers through DFS or BFS during a live assessment, StealthCoder surfaces the working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
86%

Companies that ask "Sum of Nodes with Even-Valued Grandparent"

If this hits your live OA

Sum of Nodes with Even-Valued Grandparent 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 FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The obvious mistake is trying to check a node's grandparent after you've already left its subtree. You need to carry parent and grandparent references as you recurse or queue. DFS works cleanly: pass the current node, its parent, and its grandparent through recursive calls. At each node, if the grandparent exists and is even, add the node's value to your running sum. BFS requires storing parent and grandparent alongside each node in the queue, which is messier but equally valid. The algorithmic trick isn't complex, but the implementation detail of threading context through the traversal trips candidates who haven't built that discipline. Tree traversal questions test whether you're comfortable adding parameters to DFS or designing the queue structure for BFS. If this problem hits your live OA and you hesitate on how to handle the grandparent tracking, StealthCoder runs invisibly and gives you the pattern.

Pattern tags

The honest play

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

Sum of Nodes with Even-Valued Grandparent 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 FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sum of Nodes with Even-Valued Grandparent interview FAQ

Is an 85% acceptance rate telling me this is easy?+

Not really. High acceptance usually means two things: candidates who get past the trick solve it quickly, and many skip it or fail early. The 15% who don't pass either misunderstand the grandparent logic or botch the traversal setup. This is a confidence check, not a gimme.

Should I use DFS or BFS for this?+

DFS is cleaner because you pass parent and grandparent as function parameters. BFS works but requires wrapping each node with metadata or using a custom node class. For an interview, DFS shows you understand recursion and parameter threading. BFS is the safe backup if recursion spooks you.

What's the main trap candidates fall into?+

Trying to access a node's grandparent from the node itself without having stored it during traversal. You must explicitly pass pointers or queue records down the tree. Also forgetting to handle null parents and grandparents. Even-valued grandparent means the grandparent must exist and be even.

How does this relate to other tree problems I've drilled?+

It combines basic DFS or BFS traversal with the added complexity of multi-level context tracking. If you've solved tree sum or tree search problems, you have the core skill. This just asks you to thread an extra parameter or two and add a conditional sum.

Is Salesforce still asking this, or is it stale data?+

Salesforce is listed as a company that has asked it. Frequency can't be guaranteed, but if you're interviewing there, knowing the pattern gives you a significant edge. Even if they don't ask this exact problem, the grandparent-tracking technique applies to variants.

Want the actual problem statement? View "Sum of Nodes with Even-Valued Grandparent" 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.