Does Any Root-to-Leaf Route Meet an Exact Latency Budget
Last updated: November 29, 2026
Quick Overview
Each node in a binary tree holds the latency in milliseconds of one service hop. Return whether some path from the root down to a leaf has latencies summing exactly to a target.
0
0
0 solved
Each node in a binary tree holds the latency in milliseconds of one service hop. Return whether some path from the root down to a leaf has latencies summing exactly to a target.
A Google technical screen opener framed around a request fan-out tree where each hop adds latency. The interviewer wants to see you carry state down the recursion and get the leaf condition right, then extend to returning the actual paths.
What the Interviewer Expects
- Carry the remaining budget down the tree
- Check the target only at true leaves, not at nodes with one child
- Handle negative values without pruning incorrectly
- State O(n) time and O(h) space
- Extend to listing all matching paths
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return every root-to-leaf path that meets the budget.
- Can you prune early if all latencies are non-negative?
- What if the path may start and end at any nodes going downward?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a root (possibly None) and an integer target. Return True if some root-to-leaf path sums to target. A leaf has no children. An empty tree has no paths, so it returns False even for target 0...
High-Level Design
Do an iterative DFS where each stack entry holds a node and the sum so far including that node. When we pop a leaf, compare its running sum to the target. Interior nodes push their children with updat...