FastPrepMaximum Height of Every Island
Problems/Maximum Height of Every Island

Maximum Height of Every Island

Oracle logoOracle● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Oracle onsite interview. The report gives a grid of heights and the goal of finding the highest point of each island. We chose the usual rules for the background, for which cells connect, and for the order of the output. Our version is about 75% the same as the reported question.

Given a rectangular integer matrix grid, return the maximum height of every island.

For this exercise, assume 0 represents background and every positive value represents land with that height. Two land cells belong to the same island when they share an edge; diagonal contact alone does not connect them.

Return one maximum per island in row-major discovery order: scan cells from top to bottom and left to right, and emit an island's maximum when its first cell is encountered.

Function

islandMaximumHeights(grid: int[][]) → int[]

Examples

Example 1

grid = [[1,2,0,4],[0,3,0,5],[6,0,7,0],[6,0,7,8]]return = [3,5,6,8]
grid
012301204103052607036078

The row-major scan first reaches islands with maximum heights 3, 5, 6, and 8, in that order.

Example 2

grid = [[5,0],[0,9]]return = [5,9]
grid
01050109

The two positive cells touch only diagonally, so they form separate islands whose maxima are 5 and 9.

Example 3

grid = [[2,1],[4,3]]return = [4]
grid
01021143

Every cell is connected through shared edges, so there is one island and its maximum height is 4.

Constraints

  • grid has at least one row and one column and is rectangular.
  • Every cell is a nonnegative 32-bit integer.
  • 0 is background; every positive value is land.
  • Island connectivity is horizontal and vertical only.

More Oracle Onsite Interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
  • Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Bridge Between Two IslandsCompass International Holdings · ONSITE INTERVIEWCompass International Holdings interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Number of Closed IslandsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Foreground Region SizesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • The MazeGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
  • Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public int[] islandMaximumHeights(int[][] grid) {
      // write your code here
    }
}
Checking account…