Count the Blobs
rows is a list of equal-length strings of lowercase letters, read as a grid. A blob is a largest possible group of cells that all hold the same letter and are connected to each other through up, down, left and right neighbours; diagonal neighbours do not connect. Return the number of blobs in the whole grid. A cell with no same-letter side neighbour is a blob on its own.
For example, ["aab", "abb", "ccc"] has three blobs: the three a cells, the three b cells and the row of c cells.
Example 1
The a cells touch each other by sides, so do the b cells and the c cells: three blobs.
Example 2
Every cell differs from its side neighbours, so each of the four cells is its own blob.
Constraints
1 <= len(rows) <= 101 <= len(rows[i]) <= 10, and every row has the same length- Lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- Discs After k MovesMedium
- Distinct Arrangements in OrderMedium
- Every Route Through the GardenMedium
- Fair SplitMedium
- Fill In the BracketsMedium
- Hidden Word CountMedium
- Maze EscapeMedium
- Numbers RoundMedium