Largest Contiguous Block of Damaged Inventory on a Shelf Grid
Last updated: November 29, 2026
Quick Overview
A shelf scan produces a grid where 1 marks a damaged bin and 0 an intact one. Return the size of the largest group of damaged bins connected horizontally or vertically.
Amazon
November 29, 20260
0
0 solved
A shelf scan produces a grid where 1 marks a damaged bin and 0 an intact one. Return the size of the largest group of damaged bins connected horizontally or vertically.
A common Amazon online assessment grid problem themed on damage reports from fulfillment center shelf scans. The grader checks flood fill with BFS or DFS, correct four-directional neighbors, and marking cells visited so each is counted once.
What the Interviewer Expects
- Treat the grid as a graph of 4-connected cells
- Flood fill from each unvisited damaged cell
- Count cells per component and track the maximum
- Use iterative traversal to avoid deep recursion
- State O(rows * cols) time
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 diagonal neighbors also count as connected?
- Return the number of distinct damaged groups as well.
- How would you process a grid too large for memory, row by row?
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: rectangular grid of 0s and 1s, possibly empty. Output: the size of the largest 4-connected component of 1s, or 0 if none....
High-Level Design
Scan every cell. When an unvisited 1 appears, start a BFS from it, counting cells as they are dequeued and enqueueing unvisited damaged neighbors in the four directions. Mark cells as visited when the...