⚡️ Tryprepforge
Backend Engineering Senior programming

LeetCode #1034 - Color A Border You are given a 2D grid of integers, where each integer represents the color of the cell. You need to color the border of a connected component of the grid with a new color. A border is defined as a cell that is part of the component but is adjacent to at least one cell that is not part of the component. Please implement a function that achieves this. ### Input/Output Input: - grid: List[List[int]] (the grid of colors) - row: int (starting row) - col: int (starting column) - color: int (new color) Output: - List[List[int]] (the modified grid) ### Constraints 1 <= grid.length, grid[0].length <= 50 0 <= grid[i][j] <= 100 0 <= row < grid.length 0 <= col < grid[0].length 0 <= color <= 100 ### Example Input: [[1,1,1],[1,1,0],[1,0,1]] 1 1 2 Output: [[2,2,2],[2,2,0],[2,0,1]]

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code formatting, and immersive audio explanations.

No credit card required

More Backend Engineering Interview Prep

Link copied to clipboard