Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path in Binary Matrix

med
30 min
Try to solve the Shortest Path in Binary Matrix problem.

Statement

Given a square binary matrix grid of size n x n, find the length of the shortest clear path from the top left cell to the bottom right cell.

A clear path is a sequence of cells such that every visited cell has value 00. The path starts at grid[0][0] and ends at grid[n-1][n-1]. Return the number of cells in the shortest such path. If no clear path exists, return −1-1.

Note: Movement is allowed to any of the 88 neighboring cells (horizontal, vertical, and diagonal).

Constraints:

  • n == grid.length

  • n == grid[i].length

  • 1≤1 \leq n ≤100\leq 100

  • grid[i][j] is 00 or 11

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Path in Binary Matrix

med
30 min
Try to solve the Shortest Path in Binary Matrix problem.

Statement

Given a square binary matrix grid of size n x n, find the length of the shortest clear path from the top left cell to the bottom right cell.

A clear path is a sequence of cells such that every visited cell has value 00. The path starts at grid[0][0] and ends at grid[n-1][n-1]. Return the number of cells in the shortest such path. If no clear path exists, return −1-1.

Note: Movement is allowed to any of the 88 neighboring cells (horizontal, vertical, and diagonal).

Constraints:

  • n == grid.length

  • n == grid[i].length

  • 1≤1 \leq n ≤100\leq 100

  • grid[i][j] is 00 or 11