Top-Interview-Questions--Leetcode
Top-Interview-Questions--Leetcode copied to clipboard
Reverse a Linked List in groups of given size
Given a linked list of size N. The task is to reverse every k nodes (where k is an input to the function) in the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should be considered as a group and must be reversed (See Example 2 for clarification).
LinkedList: 1->2->2->4->5->6->7->8 K = 4 Output: 4 2 2 1 8 7 6 5 Explanation: The first 4 elements 1,2,2,4 are reversed first and then the next 4 elements 5,6,7,8. Hence, the resultant linked list is 4->2->2->1->8->7->6->5.
@arushi-2298 read the instructions in ReadMe please