Amazon Interview Question

leetcode medium - i.e. dfs on island problem