Find the Middle Package on a Conveyor Linked List in One Pass

Last updated: November 29, 2026

Quick Overview

A conveyor's packages are modelled as a singly linked list whose length is unknown. Return the middle node in a single pass (the second middle when the length is even).

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


A conveyor's packages are modelled as a singly linked list whose length is unknown. Return the middle node in a single pass (the second middle when the length is even).

Shows up as an opener in Amazon phone screens before a harder follow-up. The interviewer is checking that you know the fast and slow pointer technique and can reason about even-length lists precisely.

What the Interviewer Expects
  • Use two pointers moving at speeds one and two
  • Explain why slow is at the middle when fast stops
  • Be explicit about which middle is returned for even length
  • O(n) time, O(1) space, single pass
  • Check lengths 1, 2 and 3
Key Topics to Cover
linked lists
fast and slow pointers
single pass
off-by-one reasoning
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
  • How do you return the first middle instead of the second?
  • How would you split the list into two halves for merge sort using this?
  • How would you find the node one third of the way along?
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

We receive the head of a non-empty singly linked list and cannot store the nodes in an array (the interviewer wants O(1) space). Return the middle node; for an even count such as 4, return the 3rd nod...

High-Level Design

Run two pointers from the head. slow moves one step and fast moves two steps per iteration. When fast reaches the end (either None or the last node), slow has covered half the distance, so it ...


Submit Your Answer
Markdown supported