KLA interview question

Coding round: Famous Island problem solved using simple DFS