Insufficient Nodes in Root to Leaf Paths
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given the root of a binary tree and an integer limit. A node is **insufficient** if every root-to-leaf path that passes through it has a sum of values strictly less than limit. (A leaf is a node with no children.)
Delete all insufficient nodes at the same time, together with their subtrees, and return the root of what remains. If the root itself is insufficient, return an empty tree.
The result is graded in level order. Deletion never creates a new leaf whose paths fall short: a node that survives always keeps at least one child on a path reaching limit.
Examples
Constraints
- 1 <= number of nodes <= 5000
- -10^5 <= Node.val <= 10^5
- -10^9 <= limit <= 10^9
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.