Tap here to switch tabs
Problem
Submissions

Problem: Map of Highest Peak

Try to solve the Map of Highest Peak problem.

Statement

You are given an m×nm \times n integer matrix isWater representing a map composed of land and water cells:

  • If isWater[i][j] == 0, cell (i,j)(i, j) represents a land cell.

  • If isWater[i][j] == 1, cell (i,j)(i, j) represents a water cell.

You need to assign each cell a non-negative integer height such that:

  • The height of every water cell is 00.

  • Any two adjacent cells sharing an edge (north, south, east, or west) have an absolute height difference of at most 11.

Find a valid height assignment such that the maximum height across all cells in the matrix is maximized.

Return an m×nm \times n integer matrix height where height[i][j] is the assigned height of cell (i,j)(i, j). If there are multiple valid solutions, return any of them.

Constraints:

  • m == isWater.length

  • n == isWater[i].length

  • 1≤m,n≤10001 \leq m, n \leq 1000

  • isWater[i][j] is either 00 or 11.

  • There is at least one water cell.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Map of Highest Peak

Try to solve the Map of Highest Peak problem.

Statement

You are given an m×nm \times n integer matrix isWater representing a map composed of land and water cells:

  • If isWater[i][j] == 0, cell (i,j)(i, j) represents a land cell.

  • If isWater[i][j] == 1, cell (i,j)(i, j) represents a water cell.

You need to assign each cell a non-negative integer height such that:

  • The height of every water cell is 00.

  • Any two adjacent cells sharing an edge (north, south, east, or west) have an absolute height difference of at most 11.

Find a valid height assignment such that the maximum height across all cells in the matrix is maximized.

Return an m×nm \times n integer matrix height where height[i][j] is the assigned height of cell (i,j)(i, j). If there are multiple valid solutions, return any of them.

Constraints:

  • m == isWater.length

  • n == isWater[i].length

  • 1≤m,n≤10001 \leq m, n \leq 1000

  • isWater[i][j] is either 00 or 11.

  • There is at least one water cell.