DFS-1#1410
Conversation
Flood Fill the image (01matrix.py)It seems you have submitted code for the wrong problem. The problem is "Flood Fill", but your solution is for "01 Matrix". Please double-check the problem statement and requirements. For the "Flood Fill" problem, you need to implement a BFS or DFS starting from the given pixel (sr, sc). The goal is to change the color of the starting pixel and all connected pixels (same original color) to the new color. Here are the steps you should follow:
Example code for flood fill in Python: from collections import deque
class Solution:
def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
if image[sr][sc] == color:
return image
rows, cols = len(image), len(image[0])
original_color = image[sr][sc]
q = deque()
q.append((sr, sc))
image[sr][sc] = color
directions = [(1,0), (-1,0), (0,1), (0,-1)]
while q:
r, c = q.popleft()
for dr, dc in directions:
nr, nc = r + dr, c + dc
if 0 <= nr < rows and 0 <= nc < cols and image[nr][nc] == original_color:
image[nr][nc] = color
q.append((nr, nc))
return imagePlease note the differences:
VERDICT: NEEDS_IMPROVEMENT Nearest zero (floodfill.py)It appears you have submitted a solution for the "Flood Fill" problem instead of the "Nearest Zero" problem. This is a critical mistake. Please ensure you are solving the correct problem. For the "Nearest Zero" problem, you need to compute the distance from each cell to the nearest 0. The recommended approach is to use a multi-source BFS:
This approach efficiently computes the distances by propagating from the zeros outward. Your code for Flood Fill is correct for that problem, but it does not address the Nearest Zero problem. Please review the problem statement carefully and implement the correct algorithm. VERDICT: NEEDS_IMPROVEMENT |
No description provided.