Amazon interview question

Calculated how many connected components in a grid.