terrain is a rectangular grid: 1 marks a water cell and 0 a land cell. Give every cell an integer height following these rules:
- heights are non-negative;
- water has height 0;
- cells sharing a side differ in height by at most 1.
Under these rules each cell has a highest possible height, and all of them can be reached at once. Return the grid of heights where every cell is as high as it can be.terrain=[[1, 0, 0], [0, 0, 0]] → [[0, 1, 2], [1, 2, 3]]
Water sits only in the corner. Each land cell rises exactly to its step distance from it: neighbours get 1, then 2, and the far corner 3.
terrain=[[0, 0, 0, 0], [1, 0, 0, 1]] → [[1, 2, 2, 1], [0, 1, 1, 0]]
Two water cells at both ends of the bottom row; the middle of the top row is farthest away and reaches height 2.
terrain=[[1, 0, 0], [0, 0, 0]]
[[0, 1, 2], [1, 2, 3]]
Run checks the first 3 tests in your browser. Submit checks all 70 tests on the server, hidden ones included.