Back to problems

Reverse nodes in even-length linked-list groups

Algorithm · ByteDance · Medium

Given the values of a singly linked list in their original order as an array values, partition the sequence into consecutive blocks whose intended sizes are $$1, 2, 3, \dots$$. The first block should contain one node, the second two nodes, the third three nodes, and so on. For each actual block: If the block currently has an even number of nodes, reverse the order of those nodes. If the block currently has an odd number of nodes, leave the order unchanged. The final block…

Checking your access…