Graph Theory37 sections · 1633 units
Open in Course

LeetCode 1091 Shortest Path in Binary Matrix - Problem Statement

LeetCode 1091

Problem: Shortest Path in Binary Matrix (LeetCode 10911091). You have an n×nn \times n grid where each cell is 00 (clear) or 11 (blocked). Find the shortest path from the top-left corner to the bottom-right corner. You can move in 88 directions: up, down, left, right, and diagonals.

Return the length of the shortest clear path, or 1-1 if no path exists. This is a grid BFS problem. Each cell is a node. Adjacent cells are neighbors. Run BFS starting from (0,0)(0, 0) and stop when you reach (n1,n1)(n-1, n-1).