Answer: GENERAL DYNAMICS Hiring | Online Interview Question | On-Campus OA (2022)
Answer · Posted Jun 2026
Approach Count the number of islands in the original grid. If the grid is already disconnected (0 or more than 1 island), return 0. Try removing each land cell one at a time. After removing a land cell, count the islands again. If the grid becomes disconnected, return 1. Restore the removed land cell and continue checking. If no single cell can disconnect the island, return 2. Strategy Use DFS to count the number of islands. First check whether the ...
The full answer & interview discussion are available to premium members.
Log in Create a free account