K28
Flood Fill Image Color
Problem Statement & Objective
An image is represented by an m x n integer grid image. Perform a flood fill on the image starting from the pixel (sr, sc).
Function Signature (Python)
flood_fill(image: list[list[int]], sr: int, sc: int, new_color: int) -> list[list[int]]Input & Output Contract
Output Rule:Güncellenmiş 2D matris.
System Constraints
m == goruntu.length, n == goruntu[i].length
1 <= m, n <= 50
0 <= goruntu[i][j], yeni_renk < 2^16
0 <= sr < m, 0 <= sc < nExample Execution Walkthrough
goruntu = [[1, 1, 1], [1, 1, 0], [1, 0, 1]], sr = 1, sc = 1, yeni_renk = 2
cevap: [[2, 2, 2], [2, 2, 0], [2, 0, 1]]Example Test Scenarios (3)
Example 1
Input:
[[[1,1,1],[1,1,0],[1,0,1]],1,1,2]Expected Output:
[[2,2,2],[2,2,0],[2,0,1]]Example 2: Tamamı Değişir
Input:
[[[0,0,0],[0,0,0]],0,0,2]Expected Output:
[[2,2,2],[2,2,2]]Example 3: Renk Zaten Aynı
Input:
[[[0,0,0]],0,0,0]Expected Output:
[[0,0,0]]