head of non-negative integers. The list starts and ends with a zero, and the zeros split it into blocks: between any two neighbouring zeros there is at least one non-zero value.
Replace every block with a single node holding the sum of that block, and drop the zeros. Return the head of the new list: the block sums in their original order.head=list_node([0, 2, 7, 0, 5, 0]) → [9, 5]
Between the first two zeros 2 + 7 = 9, between the second and third there is just 5. Answer: [9, 5].
head=list_node([0, 4, 4, 4, 4, 0]) → [16]
There is a single block with sum 16.
head=list_node([0, 1, 0, 30, 0, 6, 1, 0]) → [1, 30, 7]
head=list_node([0, 2, 7, 0, 5, 0])
[9, 5]
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.