Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to reverse nodes in k-group in a linked list

Hard

Problem 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; } }
Log in or sign up to run or submit your code.Log inSign up
Input
Given linked list: 1 → 2 → 3 → 4 → 5, k = 2
Expected Output
2 1 4 3 5