Shortest Path in Binary Matrix
Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path is a path from the top-left cell (0, 0) to the bottom-right cell (n-1, n-1) such that all the visited cells are 0. You may move 8-directionally (horizontal, vertical, and diagonal).
Shortest Path in Binary Matrix

Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1. A clear path is a path from the top-left cell (0, 0) to the bottom-right cell (n-1, n-1) such that all the visited cells are 0. You may move 8-directionally (horizontal, vertical, and diagonal).

Example 1:
Input: [[0,0,0],[1,1,0],[1,1,0]]
Output: 4
Input
arr =[[0,0,0],[1,1,0],[1,1,0]]

Start BFS from (0,0)

Grid (0=open, 1=blocked)

1

BFS Queue

(0,0)

Shortest Path: No Path

Start/End

Current

In Queue

Path

Variables
No variables to display
DepthFunction Call
Stack empty
0/6