Pregunta de entrevista de Amazon

Calculated how many connected components in a grid.