Advance a Warehouse Occupancy Grid One Tick In Place
Last updated: November 29, 2026
Quick Overview
A floor sensor grid marks each zone 1 (occupied) or 0 (free) and updates every tick using Conway-style rules on the eight neighbors: occupied stays occupied with 2 or 3 occupied neighbors, free becomes occupied with exactly 3. Update the grid to the next tick in place with O(1) extra space.
Amazon
November 29, 20260
0
0 solved
A floor sensor grid marks each zone 1 (occupied) or 0 (free) and updates every tick using Conway-style rules on the eight neighbors: occupied stays occupied with 2 or 3 occupied neighbors, free becomes occupied with exactly 3. Update the grid to the next tick in place with O(1) extra space.
An Amazon technical screen simulation question. The trap is updating cells while neighbors still need the old value; the interviewer wants an in-place encoding of old and new state and a discussion of how to scale to a huge or infinite floor.
What the Interviewer Expects
- Explains why naive in-place updates corrupt neighbors
- Encodes old and new state in the same cell with extra bits
- Counts eight neighbors with bounds checks
- Finishes with a second pass to shift in new state
- Discusses sparse or infinite 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
- How would you handle an infinite grid with few occupied cells?
- What if the grid is too big to fit in memory on one host?
- How would you run many ticks fast?
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: m by n grid of 0 and 1. Output: none; mutate the grid to the next state. All cells update simultaneously from the old state. Extra memory O(1)....
High-Level Design
Use bit 0 for the current state and bit 1 for the next state. In the first pass, for each cell count neighbors by reading only bit 0 (grid[r][c] & 1), decide the next state, and if it is 1 set bit 1...