As reported: NetApp SDE-1 (Bangalore, 2026), round 1 — DSA and multithreading, in person: Reverse Nodes in k-Group.
Given the head of a linked list, reverse the nodes of the list k at a time and return the modified list. If the number of nodes left at the end is less than k, leave them in their original order. Change the links, not the node values.
This is LeetCode 25 — Reverse Nodes in k-Group.
Example 1
head = [1,2,3,4,5], k = 2 -> [2,1,4,3,5]
Example 2
head = [1,2,3,4,5], k = 3 -> [3,2,1,4,5]
Constraints: 1 ≤ k ≤ n ≤ 5000; 0 ≤ Node.val ≤ 1000. Follow-up: O(1) extra memory.
Code runner format: two lines: the list as a JSON array, then k. Implement reverseKGroup(head, k); the harness prints the returned list as an array.