Implement a function to reverse nodes in k-group in a linked list
HardProblem Statement
Implement a function to reverse nodes in k-group in a linked list
Sample Input
Given linked list: 1 → 2 → 3 → 4 → 5, k = 2
Sample Output
2 1 4 3 5
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
public class Main {
public static ListNode reverseKGroup() {
// Create the linked list here
// Your code here
return null;
}
}
Input
Given linked list: 1 → 2 → 3 → 4 → 5, k = 2
Expected Output
2 1 4 3 5