Exercises/#50 Walls and Gates
#50

Walls and Gates

MediumπŸ•ΈοΈ Graphs
80 XP

Problem

Fill each empty room in a grid with the distance to its nearest gate. INF=empty room, -1=wall, 0=gate.

Examples

Input: [[INF,-1,0,INF],[INF,INF,INF,-1],[INF,-1,INF,-1],[0,-1,INF,INF]]
Output: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]
graphbfsmatrixmulti-source
AI Assistantβ€” powered by AI

Unlock hints progressively β€” start gentle, go deeper only if needed.

πŸ’‘

Level 1: Gentle Nudge

A subtle direction

πŸ—ΊοΈ

Level 2: Approach

The algorithm to use

πŸ”

Level 3: Detailed

Step-by-step guidance

50 / 150

Your Solution

⚑ JavaScript

to save progress and use AI features