Reverse Nodes in k-Group

Hard · Linked Lists · about 30 minutes

Asked at Microsoft, Google, Amazon, ByteDance, Bloomberg, Meta, Qualcomm, Two Sigma, AMD, IBM, Broadcom, Micron, Nutanix.

Cut the list into consecutive groups of k nodes and reverse the order inside every complete group. A final group shorter than k stays as it is. Relink the nodes instead of swapping values, and return the new head.