head are split, in order, into groups of growing size: the first node forms a group of one, the next two form a group of two, the next three a group of three, and so on. The last group may run out of nodes and end up shorter than its turn would allow.
Reverse the order of nodes inside every group that holds an even number of nodes (this includes a shortened last group). Leave groups of odd size as they are. Return the head of the list.head=list_node([4, 8, 1, 5, 2, 9, 6, 3]) → [4, 1, 8, 5, 2, 9, 3, 6]
The groups are [4], [8, 1], [5, 2, 9], [6, 3]. The second and the last have even length and get reversed: 4, 1, 8, 5, 2, 9, 3, 6.
head=list_node([7, 0, 2, 5]) → [7, 2, 0, 5]
The groups are [7], [0, 2], [5]. The last group ran short of three nodes and has just one, which is odd, so it stays.
head=list_node([3]) → [3]
head=list_node([4, 8, 1, 5, 2, 9, 6, 3])
[4, 1, 8, 5, 2, 9, 3, 6]
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.