EvalFrame Technical Mock Interviews & Coding Practice

Flood Fill

Easy · Graph / BFS · Algorithm problem · all problems

An image is represented by an `m x n` grid of integers `image` where `image[i][j]` represents the pixel value. You are also given three integers `sr`, `sc`, and `color`. You should perform a flood fill on the image starting from pixel `image[sr][sc]`. Return the modified image after performing the flood fill. **Examples:** ```typescript floodFill([[1,1,1],[1,1,0],[1,0,1]], 1, 1, 2) // [[2,2,2],[2,2,0],[2,0,1]] ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(m * n)
  • Space complexity: O(m * n)

In the worst case, every single pixel in the m x n grid is visited once.

Follow-Up Questions Interviewers Ask About Flood Fill

  • Why is the check orig === color crucial at the start?
    If the starting pixel already has the target color, DFS without visited tracking would cause infinite recursion and stack overflow.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.