Exercises/#150 Shortest Path in Binary Matrix
#150

Shortest Path in Binary Matrix

HardπŸ•ΈοΈ Graphs
140 XP

Problem

Given an nΓ—n binary matrix, find the length of the shortest clear path from top-left to bottom-right (8-directional). Return -1 if no path exists. 0=clear, 1=blocked.

Examples

Input: grid=[[0,1],[1,0]]
Output: 2

Input: grid=[[0,0,0],[1,1,0],[1,1,0]]
Output: 4
graphbfsmatrix
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

150 / 150

Your Solution

⚑ JavaScript

to save progress and use AI features