Painter Fill
Solutions This is a classical problem called Flood fill that can be solved in a relatively easy way: look for all pixels in the image that are connected to the start pixel by a path of the target color and changes them to the new color.
This algorithm is typically implemented using either recursion or a stack (or queue). This is a recursive implementation example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 void recursivePaintFill(vector<vector<int>>& image, int r, int c, int color, int newColor) { if (image[r][c] == color) { image[r][c] = newColor; if (r >= 1) { recursivePaintFill(image, r - 1, c, color, newColor); } if (c >= 1) { recursivePaintFill(image, r, c - 1, color, newColor); } if (r + 1 < image.
[Read More]