Uber interview question

DS & Algorithms : countIsland problem