Map of Highest Peak LeetCode solution in Python
1class Solution:2def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:3arr = collections.deque()4m, n = len(isWater), len(isWater[0])5for i in range(m):6for j in range(n):7if isWater[i][j] == 1:8arr.append((0, i, j))910ans = [[-1] * n for _ in range(m)]11while arr:12val, x, y = arr.popleft()13if ans[x][y] != -1:14continue15ans[x][y] = val16for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:17xx, yy = x + dx, y + dy18if 0 <= xx < m and 0 <= yy < n and ans[xx][yy] == -1:19arr.append((val + 1, xx, yy))20return ans