Given a singly linked list, reverse every alternate set of 3 nodes. For example, if the input is 1 -> 2 -> 3 -> 4 -> 5 -> 6, the output should be 3 -> 2 -> 1 -> 6 -> 5 -> 4.
Explanation: The list is split into two sets of 3 nodes each. The first set (1 -> 2 -> 3) is reversed to 3 -> 2 -> 1, and the second set (4 -> 5 -> 6) is reversed to 6 -> 5 -> 4.
Explanation: The list is split into two sets. The first set (7 -> 8 -> 9) is reversed to 9 -> 8 -> 7, and the second set (10 -> 11) is left as is because it has only 2 nodes.
In-place reversal of node links
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak