Tap here to switch tabs
Problem
Submissions

Problem: Coloring A Border

med
30 min
Try to solve the Coloring A Border problem.

Statement

You are given an m×nm \times n integer matrix grid, and three integers row, col, and color. Each value in grid represents the color of the square at that coordinate.

Two squares belong to the same connected component if they share the same color and are adjacent to each other in one of the four cardinal directions.

The border of a connected component is defined as all squares in that component that are situated on the boundary of the grid or are adjacent to at least one square that does not belong to the component.

Color the border of the connected component that contains the square grid[row][col] with color.

Return the modified grid.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \le m, n ≤50\le 50

  • 1≤1 \le grid[i][j], color ≤1000\le 1000

  • 0≤0 \le row <m< m

  • 0≤0 \le col <n< n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Coloring A Border

med
30 min
Try to solve the Coloring A Border problem.

Statement

You are given an m×nm \times n integer matrix grid, and three integers row, col, and color. Each value in grid represents the color of the square at that coordinate.

Two squares belong to the same connected component if they share the same color and are adjacent to each other in one of the four cardinal directions.

The border of a connected component is defined as all squares in that component that are situated on the boundary of the grid or are adjacent to at least one square that does not belong to the component.

Color the border of the connected component that contains the square grid[row][col] with color.

Return the modified grid.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 1≤1 \le m, n ≤50\le 50

  • 1≤1 \le grid[i][j], color ≤1000\le 1000

  • 0≤0 \le row <m< m

  • 0≤0 \le col <n< n