
smallestComponent
Given a matrix of characters, represented as an array of strings, your task is to find the size of the smallest connected component. A connected component is a set of elements which all share at least one edge with another member of the component, and all have the same character.
Example:
-
For
matrix = ["NNO", "ONO", "OON", "ONN"]
the output should besmallestComponent(matrix) = 2
.There are 4 components in total, of sizes
2
,3
,3
, and4
, so the smallest one has a size of2
.
Input / Output:
-
[execution time limit] 0.5 seconds
-
[input] array.string matrix
An array of strings consisting of alphanumeric characters.
Guaranteed constraints:
1 ≤ matrix.length ≤ 200
1 ≤ matrix[0].length ≤ 200
-
[output] integer
The size of the smallest connected component in the matrix.
Post Comment