โ† Amazon questions

Find distance to nearest door in a matrix

Filed under Amazon

Given a 2D grid containing empty rooms (0), doors (1), and walls (-1), calculate the distance from each empty room to the nearest door. If a room cannot reach a door, keep it as -1.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.