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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

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
linked list
fast and slow pointers
in-place reversal
merging
pointer surgery
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported