Back to problems

Reverse Linked List in Groups of K Including the Last Partial Group

Algorithm · ByteDance · Medium

Problem Description You are given the head of a singly linked list, head, together with a positive integer k. Partition the list into consecutive groups of k nodes and reverse the links within every group. Unlike the usual LeetCode 25 formulation, a final group with fewer than k nodes must also be reversed. Perform the transformation by changing the linked-list pointers in place. Do not copy the node values into an array to process them. Input Format For online judging, the…

Checking your access…