Same Letter Region
grid is a list of strings of equal length, one string per row, made of lowercase letters. Start on the cell in row r, column c. From any cell you have reached you may step up, down, left or right (never diagonally) onto a cell that holds the same letter as the starting cell, and continue from there. Return how many different cells you can reach this way, counting the starting cell itself.
Example 1
From the top-left a you can reach the a to its right and the a below it: 3 cells.
Example 2
The b cells at (2, 2), (1, 2), (1, 1) and (0, 2) are linked side to side: 4 cells. The b at (2, 0) touches that region only at a corner, so it does not count.
Constraints
1 <= rows, cols <= 100 <= r < rows,0 <= c < colsgrid[i]has lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Stones SettleEasy
- Turns to MatchEasy
- Turtle CommandsEasy
- Up and to the RightEasy
- Wireworld StepEasy
- Crush and FallMedium
- Four in a RowMedium
- Life-Like GenerationsMedium