Amazon Interview Question

a graph question with islands