Google | Find maximum height of a cell in a 2D array

Given a 2D array which represents a landscape, true being sea and false being land find the maximum possible height of the land. The height of a sea cell is 0 and height of a land cell is +1 or -1 from its neigbouring cells. It is possible for two neighbouring land cells to have the same height. Neighboring cells are only the horizontal and vertical neighbours.

landscape =  t f f f f f
             f f f f f f
             f f f f f f
             f f f f f f
             f f f f f t

Cells [0, 5] and [4, 0] have max height 4.
Comments (12)