Amazon interview question

Leetcode medium - Number of islands