Top-Interview-Questions--Leetcode icon indicating copy to clipboard operation
Top-Interview-Questions--Leetcode copied to clipboard

Reverse a Linked List in groups of given size

Open arushi-2298 opened this issue 3 years ago • 1 comments

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 avatar Oct 21 '21 16:10 arushi-2298

@arushi-2298 read the instructions in ReadMe please

KhushbooGoel01 avatar Oct 23 '21 21:10 KhushbooGoel01