Problem:
Given a 2D array of integers representing a paint canvas, where each integer represents a color, write a function that takes a point in the array and an integer representing a new color, and updates the canvas at that point along with all connected points of the same color with the new color.
Example 1:
Input:
const canvas = [[1, 2, 0, 1],
[3, 2, 4, 3],
[3, 1, 2, 0],
[1, 0, 0, 4],
]
const row = 1;
const column = 1;
const newColor = 5;
This is the classic Flood Fill problem. Starting from the given cell, you need to repaint every cell connected to it through up, down, left, or right moves that has the same original color. A standard solution uses DFS or BFS: store the starting color, traverse the connected region, and recolor each matching cell. If the starting color is already the new color, you can return early to avoid unnecessary work.