The Reverse Nodes in Even Length Groups interview question gives you a linked list where nodes are grouped sequentially: the first group has 1 node, the second has 2, the third has 3, and so on. You must reverse the nodes in every group that has an even number of nodes. The last group may be shorter than expected if not enough nodes remain — use its actual size to determine even or odd. Return the modified list.
Meta, Amazon, and Bloomberg ask this problem because it requires managing multiple concerns simultaneously: group segmentation, length counting, conditional reversal based on parity, and correct reconnection. It extends the Reverse Linked List II pattern to an iterative, multi-group context and tests candidates' ability to cleanly modularize and manage linked list state across multiple traversal phases.
The pattern is group-by-group linked list processing. Maintain a prev pointer (pointing to the node before the current group). For each group of expected size k (starting from 1): traverse to count the actual group size actual_k (may be less than k if the list ends early). If actual_k is even, reverse the group using standard reversal, then reconnect prev.next to the new group head. If odd, skip. Advance prev to the tail of the current group and increment k.
List: 5 → 2 → 6 → 3 → 9 → 1 → 7 → 3 → 8
Group 1 (size 1): [5] — odd → keep. prev=5. Group 2 (size 2): [2, 6] — even → reverse → [6, 2]. Reconnect. List: 5→6→2→3→9→1→7→3→8. prev=2. Group 3 (size 3): [3, 9, 1] — odd → keep. prev=1. Group 4 (size 4): [7, 3, 8] (only 3 left) — actual size 3 → odd → keep.
Result: 5 → 6 → 2 → 3 → 9 → 1 → 7 → 3 → 8.
k instead of actual group size for the even/odd check — the last group may be shorter.prev pointer after reversal — always update prev to the tail of the processed group.k after each group.For the Reverse Nodes in Even Length Groups coding problem, the linked list interview pattern requires combining group segmentation with conditional reversal. Modularize your code: write a helper to count actual group size and another to reverse a sublist of given length. Bloomberg and Meta interviewers appreciate clean modular solutions over monolithic loops. Practice on lists where the last group has an unexpected size to ensure your actual-size logic is correct.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Minimum and Maximum Number of Nodes Between Critical Points | Medium | Solve | |
| Split Linked List in Parts | Medium | Solve | |
| Odd Even Linked List | Medium | Solve | |
| Insert into a Sorted Circular Linked List | Medium | Solve | |
| Delete Node in a Linked List | Medium | Solve |