Python 3 simple BFS
The idea is to start BFS from each water cell at the same time. At every step, increase the height by 1 until all cells have been visited.\n\nclass Solution:\n 
The idea is to start BFS *from each water cell* at the same time. At every step, increase the height by 1 until **all cells have been visited**.\n```\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        arr, visited = deque([]), set()\n        m, n = len(isWater), len(isWater[0])\n        for i in range(m):\n            for j in range(n):\n                if isWater[i][j] == 1:\n                    arr.append((i, j, 0))\n                    visited.add((i, j))\n        res = [[0 for _ in range(n)] for _ in range(m)]\n        while arr:\n            size = len(arr)\n            for _ in range(size):\n                i, j, height = arr.popleft()\n                for x, y in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:\n                    if 0 <= x < m and 0 <= y < n and (x, y) not in visited:\n                        visited.add((x, y))\n                        arr.append((x, y, height + 1))\n                        res[x][y] = height + 1\n        return res\n```
['Breadth-First Search', 'Python', 'Python3']