Find Warehouse Floor Cells That Drain to Both Loading Exits
Last updated: November 29, 2026
Quick Overview
A warehouse floor is a grid of floor heights. Spilled liquid flows from a cell to a 4-neighbor of equal or lower height. The north and west walls drain to exit A and the south and east walls to exit B. Return all cells whose spill can reach both exits.
Amazon
November 29, 20260
0
0 solved
A warehouse floor is a grid of floor heights. Spilled liquid flows from a cell to a 4-neighbor of equal or lower height. The north and west walls drain to exit A and the south and east walls to exit B. Return all cells whose spill can reach both exits.
An Amazon onsite grid graph question framed around spill response planning on a fulfillment center floor. The interviewer looks for the reverse multi-source BFS idea: start from each exit's border and climb uphill, rather than simulating flow from every cell.
What the Interviewer Expects
- Reverse the flow direction to search from the borders inward
- Run a multi-source BFS per exit, moving to neighbors at equal or greater height
- Intersect the two reachable sets
- Explain why per-cell forward search is O((RC)^2)
- Handle single-row and single-column grids
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
- What if liquid can also flow diagonally?
- Return how many exits each cell can reach when there are four separate exits.
- How would you update the answer after one cell's height changes?
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: non-empty grid heights of integers. Output: list of [r, c] cells that can reach both exit A (row 0 or column 0) and exit B (last row or last column), in row-major order....
High-Level Design
A cell reaches exit A if there is a non-increasing path from it to the A border. Reversed, that is a non-decreasing path from the border to the cell. So seed a BFS with every border cell of A and expa...