Question bank › Linked List
Dsa Linked List Medium

Reverse Nodes in Groups

Given a linked list, you need to reverse the list in groups of size k. If the number of nodes is not a multiple of k, then the remaining nodes should remain as they are. Implement a function that reads the linked list's elements and the value k, and outputs the new head of the reversed list in space-separated format. Input: The first line contains the integer n, the number of nodes in the linked list (1 <= n <= 1000). The second line contains n integers, the values of the nodes in the linked list. The third line contains an integer k (1 <= k <= n). Output: Print the elements of the reversed linked list in space-separated format. Example: Input: 6 1 2 3 4 5 6 2 Output: 2 1 4 3 6 5

Key concepts

linked_listgroup_reversal

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.