Amazon interview question

Number of Islands variation leetcode