Find Each Island's Maximum Height
Last updated: August 18, 2026
Quick Overview
The question asks the candidate to find the maximum height of each island represented in a 2D grid, where islands are formed by connected '1's and the rest of the grid is filled with '0's.
Oracle
August 18, 20261
0
10 solved
The question asks the candidate to find the maximum height of each island represented in a 2D grid, where islands are formed by connected '1's and the rest of the grid is filled with '0's.
This question is typically asked in the onsite coding round to evaluate a candidate's problem-solving and coding skills. The interviewer is looking for the candidate's ability to apply algorithms to traverse grids, handle edge cases, and optimize their solution. It tests both their understanding of depth-first search (DFS) or breadth-first search (BFS) and their coding proficiency in a real-time setting.
What the Interviewer Expects
- Clearly explain the approach to identify islands in the grid.
- Implement an efficient algorithm to traverse the grid and calculate maximum heights.
- Discuss edge cases and how they are handled in the solution.
- Provide a well-structured code with comments for clarity.
- Analyze the time and space complexity of the solution.
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you optimize your solution for larger grids?
- Can you explain how you would handle a grid with varying heights?
- What alternative algorithms could be used to solve this problem?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Approach
To solve the problem, we will use a depth-first search (DFS) algorithm to traverse the grid. We will iterate through each cell in the grid, and upon encountering a '1', we will initiate a DFS to explo...
Algorithm
Here is the Python code implementing the DFS algorithm:
def maxIslandHeight(grid):
if not grid:
return []
max_heights = []
rows, cols = len(grid), len(grid[0])
visi...