Be the first user to complete this post
|Add to List|
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)
- Find all possible combinations with sum K from a given number N(1 to N) with the repetition of numbers is allowed Medium