A healthcare imaging team is building an annotation tool used by radiologists to mark regions (e.g., a tumor boundary) on 2D slices. Each slice is represented as an m x n grid of integer pixel labels. When a radiologist clicks a pixel, the tool should recolor the entire 4-directionally connected region (up, down, left, right) that shares the same original label.
Implement a flood fill operation.
You are given:
image: a 2D grid list[list[int]] of size m x nsr, sc: the starting row and columnnew_color: the integer label to paintReturn the modified image after replacing the color of the starting pixel and all pixels connected to it (4-directionally) that have the same original color with new_color.
Two pixels are connected if they share an edge (no diagonals).
Example 1
image = [[1,1,1],[1,1,0],[1,0,1]], sr = 1, sc = 1, new_color = 2[[2,2,2],[2,2,0],[2,0,1]](1,1) has original color 1.1s connected to (1,1) via up/down/left/right are recolored to 2.1 at (2,2) is not connected (it’s separated by 0s), so it remains 1.Example 2
image = [[3,3],[3,3]], sr = 0, sc = 0, new_color = 3[[3,3],[3,3]]image in-place).(sr, sc) is out of bounds, assume inputs are valid per constraints.1 <= m, n <= 2000 <= image[r][c] <= 10^40 <= sr < m, 0 <= sc < n0 <= new_color <= 10^4