Flood Fill Algorithm Task
Assist Ninja in altering the color of a specific region in his photo. Given the image as a 2D array where each pixel is a positive integer, update the color of a specified pixel and the adjacent pixels with the same color to a new color.
Explanation:
The task requires changing the color of a given pixel located at coordinates (row, column) and its directly adjacent same-colored pixels (up, down, left, right; not diagonally) in the image to a new specified color.
Input:
M (rows in image), N (columns), and the image matrix of dimensions MxN.
Coordinates X, Y (row and column of the pixel) and the new color C.
Output:
Print the updated image matrix after applying the new color.
Example:
Consider a 4x4 image matrix. Starting pixel is located at (1, 2) with new color 8. Original value is 3. The new image shows altered pixels.
Original: [[1, 1, 1, 1],
[1, 3, 3, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]
New: [[1, 1, 1, 1],
[1, 8, 8, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]]
Constraints:
- 1 <= T <= 100
- 1 <= M, N <= 50
- 0 <= X < M
- 0 <= Y < N
- 1 <= Image[i][j], C <= 105
- Time Limit: 1 second
The Flood Fill Algorithm is used to change the color of a particular region in an image and all its adjacent same-colored pixels.
The image is represented as a 2D array of positive integers
The starting...read more
Top ShareChat Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month