Answer: Cisco OA Question 2024 June | Graphs | on-campus

Answer · Posted Jun 2026

Solution: Pacific Atlantic Water Flow — Double DFS Approach Instead of simulating flow from each cell to the ocean (which is computationally expensive), we can work backwards. We find all cells that can be reached from the oceans by moving to cells of equal or greater height. We maintain two boolean tables: pacific and atlantic. We initiate DFS traversals from the cells directly bordering the Pacific Ocean (top and left boundaries) and mark reachable nodes. We do the same for ...

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

Log in Create a free account