Reorder a Pick List by Alternating First and Last Items
Last updated: November 29, 2026
Quick Overview
Given a singly linked pick list L0, L1, ..., Ln, reorder it in place to L0, Ln, L1, Ln-1, L2, ... so a picker alternates between the two ends of an aisle. Do not create new nodes.
Amazon
November 29, 20260
0
0 solved
Given a singly linked pick list L0, L1, ..., Ln, reorder it in place to L0, Ln, L1, Ln-1, L2, ... so a picker alternates between the two ends of an aisle. Do not create new nodes.
This tests whether a candidate can compose three standard list operations under pressure, a pattern Amazon onsite coding rounds like. The interviewer checks decomposition, clean helper functions and correct termination of the merged list.
What the Interviewer Expects
- Find the middle with fast and slow pointers
- Cut the list and reverse the second half in place
- Interleave the halves, terminating with None
- O(n) time and O(1) extra space
- Explain why the first half is the same length or one longer
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
- How would you undo the reordering?
- What if you could use O(n) memory: what is the simplest approach?
- How would you reorder into L0, Ln, Ln-1, L1, L2, ... instead?
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 is the head of a singly linked list, possibly empty. Rearrange the existing nodes (values must not be copied around) so the order alternates first, last, second, second last, and so on. Return n...
High-Level Design
Three steps. First, find the end of the first half with slow and fast pointers. Second, detach the second half and reverse it. Third, weave: take one node from the first half, then one from the revers...