Amazon Warehouse 01 Matrix BFS
Amazon Warehouse 01 Matrix BFS
MediumQueues33% accepted
Amazon warehouse grid has 0s (empty) and 1s (packages). For each cell find the distance to the nearest 0. Distance = number of steps horizontally or vertically.
Approach
Find shortest distance from each cell to nearest 0 using multi-source BFS.
Input
3 3
0 0 0
0 1 0
0 0 0
Output
0 0 0
0 1 0
0 0 0
More Queues problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards