Reverse Nodes in Even Length Groups

Medium · Linked Lists · about 25 minutes

Asked at Amazon, Google, Microsoft.

Split a linked list into consecutive groups of sizes 1, 2, 3, … (the last group may be shorter). Reverse every group whose actual length is even, and return the head.