[Python3] bfs
\n\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        m, n = len(isWater), len(isWater[0]) # dimensions \n      
\n```\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        m, n = len(isWater), len(isWater[0]) # dimensions \n        queue = [(i, j) for i in range(m) for j in range(n) if isWater[i][j]]\n        \n        ht = 0\n        ans = [[0]*n for _ in range(m)]\n        seen = set(queue)\n        \n        while queue: \n            newq = []\n            for i, j in queue: \n                ans[i][j] = ht\n                for ii, jj in (i-1, j), (i, j-1), (i, j+1), (i+1, j): \n                    if 0 <= ii < m and 0 <= jj < n and (ii, jj) not in seen: \n                        newq.append((ii, jj))\n                        seen.add((ii, jj))\n            queue = newq\n            ht += 1\n        return ans \n```\n\nAlternative implementation\n```\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        m, n = len(isWater), len(isWater[0]) # dimensions \n        \n        ans = [[-1]*n for _ in range(m)]\n        queue = deque()\n        for i in range(m): \n            for j in range(n):\n                if isWater[i][j]:\n                    queue.append((i, j))\n                    ans[i][j] = 0\n\n        while queue: \n            i, j = queue.popleft()\n            for ii, jj in (i-1, j), (i, j-1), (i, j+1), (i+1, j): \n                if 0 <= ii < m and 0 <= jj < n and ans[ii][jj] == -1: \n                    ans[ii][jj] = 1 + ans[i][j]\n                    queue.append((ii, jj))\n        return ans \n```
['Python3']