Problem
Ask
Submissions

Problem: 01 Matrix

Medium
30 min
Explore how to determine the shortest distance from every cell to the nearest zero in an m by n binary matrix. This lesson guides you through applying dynamic programming methods to efficiently solve this problem, helping you build skills essential for coding interviews.

Statement

Given an m×nm \times n binary matrix, mat, find the distance from each cell to the nearest 00. The distance between two adjacent cells is 11. Cells to the left, right, above, and below the current cell will be considered adjacent.

Constraints:

  • 11 \leq mat.row , mat.col50\leq 50

  • 11 \leq mat.row * mat.col 2500\leq 2500

  • mat[i][j] {0,1}\in \{0, 1\}

  • There is at least one 00 in mat.

Problem
Ask
Submissions

Problem: 01 Matrix

Medium
30 min
Explore how to determine the shortest distance from every cell to the nearest zero in an m by n binary matrix. This lesson guides you through applying dynamic programming methods to efficiently solve this problem, helping you build skills essential for coding interviews.

Statement

Given an m×nm \times n binary matrix, mat, find the distance from each cell to the nearest 00. The distance between two adjacent cells is 11. Cells to the left, right, above, and below the current cell will be considered adjacent.

Constraints:

  • 11 \leq mat.row , mat.col50\leq 50

  • 11 \leq mat.row * mat.col 2500\leq 2500

  • mat[i][j] {0,1}\in \{0, 1\}

  • There is at least one 00 in mat.