Spiral Pick Order Through a Rectangular Storage Grid
Last updated: November 29, 2026
Quick Overview
A picker robot starts at the top-left bin of an m by n storage grid and walks the outer ring clockwise, then the next ring inward, and so on. Return the bin labels in the order the robot visits them.
Amazon
November 29, 20260
0
0 solved
A picker robot starts at the top-left bin of an m by n storage grid and walks the outer ring clockwise, then the next ring inward, and so on. Return the bin labels in the order the robot visits them.
An Amazon phone screen simulation question in warehouse clothing. The interviewer is checking boundary bookkeeping: four shrinking limits, and not double-counting the last row or column when the grid is a single strip.
What the Interviewer Expects
- Maintains top, bottom, left, right bounds
- Walks right, down, left, up per ring
- Guards the left and up passes for single row or column rings
- Visits every cell exactly once
- Runs in O(m * n)
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
- Produce the counterclockwise order instead.
- Fill a new n by n grid with 1..n^2 in spiral order.
- Return only the kth bin visited without building the whole 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: a list of m rows, each of length n (possibly m or n equal to 1, or the grid empty). Output: list of all m * n values in clockwise spiral order from the top-left....
High-Level Design
Keep four bounds. Each ring: walk the top row from left to right, then increment top; walk the right column from top to bottom, then decrement right; if rows remain, walk the bottom row right to left ...