← Questions

Walls and gates

0
MetaCodingLast asked Jan 2026

A grid holds walls, gates and empty rooms. Fill every empty room with the distance to its nearest gate, leaving rooms that cannot reach a gate untouched. Use one multi-source BFS starting from all gates.

Write and test your solution herePython in your browser, the question's tests level by level, saved for you.Sign in to start coding