Reverse a Linked List in groups of given size ‘K’
Objective: Given a linked list and integer ‘k’, write an algorithm to reverse the linked list in groups of size ‘k’.
- Earlier we have seen how to reverse a linked list, solution for reverse the linked list in groups of size will be extension of this solution.
- Reverse first ‘k’ nodes of the linked list, the kth node will be a new head, return it.
- Make a recursive call to rest of the list and attach it to the last node.(See the picture below)