Find largest island area
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates a candidate's ability to perform grid-based graph traversal and manage visited state, testing algorithmic skills in connected components and traversal techniques within algorithms and data structures.
Constraints
- 1 <= m, n <= 200
- grid is an m x n matrix of integers
- grid[i][j] is 0 or 1
- Adjacency is 4-directional only
- Expected time complexity: O(m*n)
Hints
- Use DFS or BFS to explore each unvisited land cell and compute its island area.
- Track visited cells to avoid recounting and infinite loops.
- Check bounds carefully when exploring the four neighbors of a cell.