Merge Nodes in Between Zeros
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 head of a linked list of integers that **begins and ends with a 0 node**, and never has two 0 nodes next to each other. The zeros split the list into groups of non-zero values.
Replace each group (the nodes strictly between two consecutive zeros) with a single node holding the group's sum, and drop all of the 0 nodes. Return the head of the new list, with the sums in the same order as their groups appeared.
Examples
Constraints
- The number of nodes is in `[3, 2 * 10^5]`.
- `0 <= Node.val <= 1000`
- No two consecutive nodes both have value `0`.
- The first and last nodes have value `0`.
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.