Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up
Problem Submissions Solution

Flood Fill

Difficulty: Medium

Acceptance: 69.00%

Points: 30.00

You are given a 2D grid image[][] representing an image, where each cell contains a color value. You are also given a starting cell (sr, sc) and a new color newColor. Your task is to replace the color of the starting cell and all 4-directionally connected cells having the same original color with newColor. Cells are connected only in four directions: Up, Down, Left, Right. Return the updated image after performing the flood fill.

Topics

Companies

Articles

Examples:

N/A

Constraints:
  • m == image.length
  • n == image[i].length
  • 1 = m, n = 50
  • 0 = image[i][j], newColor < 216
  • 0 = sr < m
  • 0 = sc < n
Companies:
Amazon Microsoft Apple Samsung Visa + 1 more
Topics:
Recursion
Locked Content
Access Restricted: Please Login to access the code editor and test cases.