Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Shortest Path in Binary Matrix

Medium Graphs

In an n x n grid of 0s and 1s, find the length of the shortest clear path from the top-left to the bottom-right cell. A clear path only uses 0 cells and may move in all 8 directions. The length is the number of cells visited. Print -1 if no path exists.

Constraints

1 <= n <= 100

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.