A drawing canvas is a grid of R rows and C columns; each cell holds a single color given as a digit 0-9. A paint-bucket fill starts at a chosen cell and spreads to every cell reachable through shared edges (up, down, left, right) while staying on cells whose color equals the starting cell's color.
Report how many cells the fill would cover, counting the starting cell itself.
Line 1: two integers R and C.
Next R lines: a string of exactly C digit characters, the colors of that row.
Last line: two integers r and c (0-indexed), the starting cell's row and column.
A single integer: the number of cells covered by the fill (always at least 1).
0-9.Example 1
Input
3 3 110 110 002 0 0
Expected
4
Explanation
Starting at (0,0) with color 1, the fill spreads over the four connected 1-cells at (0,0),(0,1),(1,0),(1,1): size 4.
Example 2
Input
3 3 110 110 002 2 2
Expected
1
Explanation
Starting at (2,2) with color 2, both neighbors are color 0, so only the single cell is covered: size 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →