Remove Zero Sum Consecutive Nodes from Linked List
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
Given the head of a linked list of integers, delete runs of consecutive nodes whose values sum to 0, and return the head of what remains ([] if nothing remains).
Because different deletion orders can leave different lists, use this exact procedure: read the nodes **left to right**, appending each one to a result list. Immediately after each append, if some **suffix** of the result list sums to 0, delete that suffix (there is at most one such suffix, since the result never contains a zero-sum run before this step). Continue with the next input node.
Tracking prefix sums of the result list in a hash map makes each step amortized O(1).
Examples
Constraints
- 1 <= number of nodes <= 1000
- -1000 <= Node.val <= 1000
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.