Answer: Swiggy OA Question 2024 July | Graphs | on-campus

Answer · Posted Jun 2026

Solution: Number of Islands — DFS Flood Fill Approach We use DFS Flood Fill. We iterate through every cell of the grid. Whenever we find an unvisited land cell ('1'), we: Increment the island counter by 1. Launch a DFS from that cell to mark all connected land cells as visited by setting them to '0' (sinking the island). By the end, every island has been counted and fully consumed. The grid modification acts as our visited set, saving extra ...

The full answer & interview discussion are available to premium members.

Log in Create a free account