Flood Fill
In computer graphics, an uncompressed raster image is presented as a matrix of numbers. Each entry of the matrix represents the color of a pixel. A flood fill algorithm takes a coordinate r, c
and a replacement color, and replaces all pixels connected to r, c
that have the same color (i.e., the pixels connected to the given coordinate with of same color and all the other pixels connected to the those pixels of the same color) with the replacement color. (e.g. MS-Paint's paint bucket tool).
Input
r
: rowc
: columnreplacement
: replacement colorimage
: an 2D array of integers representing the image
Output
the replaced image
Examples
Example 1:
Input:
1r = 2 2c = 2 3replacement = 9 4arr = [[0,1,3,4,1],[3,8,8,3,3],[6,7,8,8,3],[12,2,8,9,1],[12,3,1,3,2]]
Output: [[0,1,3,4,1],[3,9,9,3,3],[6,7,9,9,3],[12,2,9,9,1],[12,3,1,3,2]]
Explanation:
From
10 1 3 4 1 23 8 8 3 3 36 7 8 8 3 412 2 8 9 1 512 3 1 3 2
to
10 1 3 4 1 23 9 9 3 3 36 7 9 9 3 412 2 9 9 1 512 3 1 3 2
Try it yourself
Solution
Title
Script
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
Contrary to popular belief, Lorem
Ipsum
is not simply random text.
1 >>> a = [1, 2, 3] 2 >>> a[-1] 3 3