As reported: Amazon SDE-2 onsite round 1 (Chennai, Oct 2025): 15–20 minutes of Leadership Principles, then two LeetCode problems in Amazon's own editor — code did not have to run, but writing it out and stating time and space complexity mattered.
Given the head of a linked list, repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. Return the head of the final list. Any valid final list is accepted.
This is LeetCode 1171 — Remove Zero Sum Consecutive Nodes from Linked List.
Examples
head = [1,2,-3,3,1] -> [3,1] ([1,2,1] is also accepted)
head = [1,2,3,-3,4] -> [1,2,4]
head = [1,2,3,-3,-2] -> [1]
Constraints: 1 ≤ number of nodes ≤ 1000; −1000 ≤ Node.val ≤ 1000.
Code runner format: one line: the list as a JSON array. Implement removeZeroSumSublists(head); the harness checks that your result has no zero-sum run left and can be obtained from the input by deleting zero-sum runs, and prints "ok".