Amazon Interview Question

leetcode medium - number of islands