Pergunta de entrevista da empresa Microsoft

A 2d array question about connected islands.