MEDIUMasked at 8 companies

Path Sum II

A medium-tier problem at 60% community acceptance, tagged with Backtracking, Tree, Depth-First Search. Reported in interviews at Arista Networks and 7 others.

Founder's read

Path Sum II is a classic backtracking problem that shows up in interviews at Amazon, Meta, TikTok, and Oracle. You're given a binary tree and a target sum, and you need to find all root-to-leaf paths that add up to that sum. The 60% acceptance rate tells you most people get tripped up on the implementation details, not the concept. Many candidates know they need backtracking but fail on managing the path state or properly pruning the tree. If this problem hits your live OA and you blank on the exact recursion pattern, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
8
Difficulty
MEDIUM
Acceptance
60%

Companies that ask "Path Sum II"

If this hits your live OA

Path Sum II 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 trap here is thinking DFS alone is enough. You need to track three things simultaneously: the current node, the running sum, and the actual path (list of node values). Most failures come from either mutating the path incorrectly (adding to it but forgetting to remove during backtrack) or checking the sum condition at the wrong tree node. The pattern is: recurse on left and right children, accumulate the current node's value into the path, and only record a complete path when you hit a leaf node AND the sum matches. Common mistake: checking the condition before you've confirmed you're at a leaf. When candidates freeze on the exact backtracking rhythm during an assessment, StealthCoder bypasses the mental block and delivers a clean recursive template that handles path management correctly.

Pattern tags

The honest play

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

Path Sum II 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.

Path Sum II interview FAQ

Why isn't a simple DFS enough for this problem?+

DFS tracks traversal but not state. You need backtracking because you must maintain a path list that changes as you explore and shrinks as you backtrack. Without removing nodes from the path after recursion returns, you'll pollute all subsequent path attempts. That's why the acceptance rate sits at 60% instead of 80%.

Is this still asked at big tech companies?+

Yes. Amazon, Meta, TikTok, Oracle, and others in the input data report asking it. It's not the hardest tree problem, but it's a reliable medium-difficulty screener that filters for clean backtracking discipline.

What's the most common implementation mistake?+

Forgetting to remove the current node from the path after the recursive call returns. You add the node, recurse, then must pop it before returning. Skip that step and you'll carry phantom nodes into sibling subtrees.

How does Path Sum II relate to general backtracking topics?+

It's a textbook backtracking use case: explore a decision tree (left/right children), maintain mutable state (the path), commit and undo that state (add/remove node). If you understand this pattern deeply, you handle combinations, permutations, and constraint problems better.

Should I use pass-by-reference or pass-by-value for the path list?+

Pass by reference and mutate it. Create new copies and you'll waste memory and slow down. Mutate and backtrack cleanly. That's the point of learning backtracking: managing shared state efficiently, which is what the interviewer actually cares about.

Want the actual problem statement? View "Path Sum II" 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.