FunctionRacerProblemsRace

Count the Blobs

MediumRecursionPython, JavaScript, TypeScript, Java, C++

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

rows ["aab","abb","ccc"]
returns 3

The a cells touch each other by sides, so do the b cells and the c cells: three blobs.

Example 2

rows ["ab","ba"]
returns 4

Every cell differs from its side neighbours, so each of the four cells is its own blob.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems