{"id":22513854,"url":"https://github.com/emahtab/flood-fill","last_synced_at":"2026-01-30T11:17:19.702Z","repository":{"id":79525512,"uuid":"244191142","full_name":"eMahtab/flood-fill","owner":"eMahtab","description":"Flood Fill","archived":false,"fork":false,"pushed_at":"2020-03-01T17:47:26.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:25:44.372Z","etag":null,"topics":["dfs","flood-fill","leetcode","problem-solving","recursion"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-01T17:17:09.000Z","updated_at":"2020-03-01T17:47:28.000Z","dependencies_parsed_at":"2023-06-25T22:14:56.857Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/flood-fill","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fflood-fill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fflood-fill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fflood-fill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fflood-fill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/flood-fill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952130,"owners_count":20699430,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dfs","flood-fill","leetcode","problem-solving","recursion"],"created_at":"2024-12-07T03:14:44.004Z","updated_at":"2026-01-30T11:17:19.642Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flood Fill\n## https://leetcode.com/problems/flood-fill\n\nAn image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).\n\nGiven a coordinate (sr, sc) representing the starting pixel (row and column) of the flood fill, and a pixel value newColor, \"flood fill\" the image.\n\nTo perform a \"flood fill\", consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the starting pixel, plus any pixels connected 4-directionally to those pixels (also with the same color as the starting pixel), and so on. Replace the color of all of the aforementioned pixels with the newColor.\n\nAt the end, return the modified image.\n```\nExample 1:\n\nInput: \nimage = [[1,1,1],[1,1,0],[1,0,1]]\nsr = 1, sc = 1, newColor = 2\nOutput: [[2,2,2],[2,2,0],[2,0,1]]\n\nExplanation: \nFrom the center of the image (with position (sr, sc) = (1, 1)), all pixels connected \nby a path of the same color as the starting pixel are colored with the new color.\nNote the bottom corner is not colored 2, because it is not 4-directionally connected\nto the starting pixel.\n```\n**Note:**\n1. The length of image and image[0] will be in the range [1, 50].\n2. The given starting pixel will satisfy 0 \u003c= sr \u003c image.length and 0 \u003c= sc \u003c image[0].length.\n3. The value of each color in image[i][j] and newColor will be an integer in [0, 65535].\n\n\n\n# Implementation : DFS\n```java\nclass Solution {\n    public int[][] floodFill(int[][] image, int sr, int sc, int newColor) {\n        if(newColor == image[sr][sc])\n            return image;\n        fill(image, sr, sc, image[sr][sc], newColor);\n        return image;\n    }\n    \n    private void fill(int[][] image, int i, int j, int oldColor, int newColor){\n        if(i \u003c 0 || i \u003e= image.length || j \u003c 0 || j \u003e= image[i].length || image[i][j] != oldColor){\n            return;\n        }\n        \n        image[i][j] = newColor;\n        fill(image, i, j+1, oldColor, newColor);\n        fill(image, i, j-1, oldColor, newColor);\n        fill(image, i+1, j, oldColor, newColor);\n        fill(image, i-1, j, oldColor, newColor);\n    }\n}\n```\n\n\n# References :\n1. https://www.youtube.com/watch?v=GRSy2cLxTxE\n2. https://www.youtube.com/watch?v=TClRuEZ-uDg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fflood-fill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fflood-fill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fflood-fill/lists"}