Nearest Exit for a Picker Entering a Warehouse Aisle Maze
Last updated: November 29, 2026
Quick Overview
A warehouse floor is a grid of open cells and racks. Given the picker's entrance cell, return the fewest steps to reach any open border cell other than the entrance, or -1 if none is reachable.
Amazon
November 29, 20260
0
0 solved
A warehouse floor is a grid of open cells and racks. Given the picker's entrance cell, return the fewest steps to reach any open border cell other than the entrance, or -1 if none is reachable.
Amazon online assessments often feature unweighted grid shortest paths framed around fulfillment center layouts. The interviewer checks BFS level counting, marking cells visited when enqueued, and excluding the entrance even though it lies on the border.
What the Interviewer Expects
- Use BFS because every step costs one
- Mark cells visited at enqueue time to avoid duplicates
- Exclude the entrance itself from counting as an exit
- Return the level when an exit is first dequeued or discovered
- Handle a fully enclosed entrance
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 find the exit that minimizes steps plus a per-exit congestion penalty?
- How would you answer for many entrances at once?
- What changes if some cells take two steps to cross?
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: grid of '.' (open) and '+' (rack), entrance (r, c) which is open. Moves are four-directional. An exit is an open cell on the outer border that is not the entrance. Output: minimum number of ste...
High-Level Design
Run BFS from the entrance, storing (r, c, steps). When generating an open, unvisited neighbor, check whether it is on the border; if so it is an exit (it cannot be the entrance, since the entrance is ...