Interleave a Linked List's Front and Back Halves for a Carousel
Last updated: November 29, 2026
Quick Overview
Reorder a singly linked list L0 -> L1 -> ... -> Ln into L0 -> Ln -> L1 -> Ln-1 -> L2 -> ... in place, so a Discover carousel alternates between the freshest and oldest cards.
0
0
0 solved
Reorder a singly linked list L0 -> L1 -> ... -> Ln into L0 -> Ln -> L1 -> Ln-1 -> L2 -> ... in place, so a Discover carousel alternates between the freshest and oldest cards.
A Google onsite problem that composes three linked list primitives: find the middle, reverse a half, merge alternately. The interviewer checks whether you cut the list cleanly so no cycle is created and whether the code stays O(1) space.
What the Interviewer Expects
- Split at the middle with slow and fast pointers
- Terminate the first half to avoid a cycle
- Reverse the second half in place
- Weave the halves alternately
- O(n) time and O(1) extra space; no array copy
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Do it with an array of nodes and compare trade-offs.
- Interleave three cards from the front for every one from the back.
- Undo the reorder to recover the original list.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head of a singly linked list.
- Output: none; the list is reordered in place as L0, Ln, L1, Ln-1, ...
- O(1) extra space, nodes not values are moved....
High-Level Design
Three steps. (1) Find the end of the first half: slow and fast start at the head, fast moves two steps, and slow ends at the middle (first middle for even lengths). (2) Detach the second half with `se...