04. Linked List Group Reverse
β GFG solution to the Linked List Group Reverse problem: reverse every k nodes in a linked list including remaining nodes using recursive and iterative approaches. π
π§© Problem Description
π Examples
Example 1
Input: k = 2,
Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> 6
Output: 2 -> 1 -> 4 -> 3 -> 6 -> 5
Explanation: Linked List is reversed in groups of size k = 2.
Groups: [1,2] -> [2,1], [3,4] -> [4,3], [5,6] -> [6,5]Example 2
Input: k = 4,
Linked List: 1 -> 2 -> 3 -> 4 -> 5 -> 6
Output: 4 -> 3 -> 2 -> 1 -> 6 -> 5
Explanation: Linked List is reversed in groups of size k = 4.
Groups: [1,2,3,4] -> [4,3,2,1], [5,6] -> [6,5] (remaining nodes also reversed)Example 3
π Constraints
β
My Approach
Recursive Group Processing + Fast-Pointer
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated