You're building the paint bucket for a pixel-art editor. The canvas image is a grid of color numbers. Clicking pixel (row, col) with color color repaints that pixel and every pixel connected to it (up, down, left, or right, through pixels of the same original color) with color.
Write paintBucket(image, row, col, color) that applies the fill and returns the canvas. Diagonal pixels are not connected.
Input: image = [[1,1,1],[1,1,0],[1,0,1]], row = 1, col = 1, color = 2 Output: [[2,2,2],[2,2,0],[2,0,1]]
Every 1 connected to the center becomes 2. The bottom-right 1 only touches the others diagonally, so it stays.
Input: image = [[0,0],[0,0]], row = 0, col = 0, color = 0 Output: [[0,0],[0,0]]
The pixel already has color 0, so nothing changes.
1 <= image.length, image[i].length <= 500 <= image[i][j], color <= 65535(row, col) is inside the canvas.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #420 Paint Bucket Tool. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.