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]

Raid planner

Solutions This is the first graph problem at Coding Gym, specifically focusing on determining if a path exists between two nodes. To make it a suitable introductory challenge, we’ve applied a few simplifications: the graph is undirected (meaning each edge can be traversed in both directions), and the input format is designed to be straightforward - we’ll explain why shortly. Additionally, the graph contains no isolated nodes or self-edges. The input format is favorable for storing the graph as an adjacency list, a well-known graph representation where each node is associated with a list of its neighbors (the nodes it’s connected to by edges). [Read More]
graphs