Tap here to switch tabs
Problem
Submissions

Problem: 01 Matrix

01 Matrix asks you to replace each cell in a binary matrix with its distance to the nearest zero, counting only horizontal and vertical moves between adjacent cells.

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:

  • 1≤1 \leq mat.row , mat.col≤50\leq 50

  • 1≤1 \leq mat.row * mat.col ≤2500\leq 2500

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

  • There is at least one 00 in mat.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: 01 Matrix

01 Matrix asks you to replace each cell in a binary matrix with its distance to the nearest zero, counting only horizontal and vertical moves between adjacent cells.

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:

  • 1≤1 \leq mat.row , mat.col≤50\leq 50

  • 1≤1 \leq mat.row * mat.col ≤2500\leq 2500

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

  • There is at least one 00 in mat.