As reported: Goldman Sachs Associate Superday, data structures round (Compliance Engineering, 2025): Reverse Nodes in k-Group, then Longest Increasing Subsequence.
Reverse the nodes of a linked list k at a time and return the new head. If the number of nodes left at the end is smaller than k, leave them as they are. Only change links, not 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]
Example 3
head = [1,2,3,4,5], k = 1
-> [1,2,3,4,5]
Constraints: 1 ≤ k ≤ n ≤ 5000; 0 ≤ Node.val ≤ 1000.
Code runner format: one JSON value per line: head, then k (LeetCode's test-case format). Implement reverseKGroup(head, k); the harness prints the result as JSON.