Back to problems

Maximum Height of Each Island

Algorithm · Oracle · Medium

You are given a rectangular grid heights with m rows and n columns. A cell containing 0 is water. A cell containing a positive integer is land, and that integer represents its height. Two land cells are connected if they are directly adjacent horizontally or vertically. Each maximal connected group of land cells forms an island. For every island, compute its maximum cell height. Scan the grid from top to bottom, and within each row from left to right. Output the maxima in…

Checking your access…