Practice Coloring A Border
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location. Two squares are called adjacent if they are next to each other in any of the 4 directions. Two squares belong to the same connected component if they have the same color and they are adjacent. The border of a connected component is all the squares in the connected component that are either adjacent to (at least) a square not in the component, or on the boundary of the grid (the first or last row or column). You should color the border of the connected component that contains the square grid[row][col] with color. Return the final grid.
Source: Coloring A Border on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[1,1],[1,2]], row = 0, col = 0, color = 3
[[3,3],[3,2]]
# Example 2
grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3
[[1,3,3],[2,3,3]]
# Example 3
grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2
[[2,2,2],[2,1,2],[2,2,2]]
Constraints
Related LeetCode Problems
Practice more problems similar to Coloring A Border.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.