Amazon Interview Question

similar to num islands on leetcode