Python 3 | Greedy, Multi-source BFS | Explanation
Explanation\n- Start from water nodes and BFS until all heights are found\n- NOTE: You don\'t need to worry about getting a skewed peak (by skewed, I mean a hei
### Explanation\n- Start from *water* nodes and BFS until all heights are found\n- NOTE: You don\'t need to worry about getting a skewed peak (by *skewed*, I mean a height with difference greater than 1 on some neighbors), because it will never be possible\n\t- For example: following situation will never be possible\n\t\t```\n\t\t1 2\n\t\t1 0\n\t\t```\n\t- This is because we are using BFS and increment at 1 for each step, in this case, for any node at `(i, j)`, whenever the value is assigned, it will be the highest possible value\n\t- If the same node is re-visited in later step, it can only be the same or larger (larger will be wrong, since you will get a skewed peak), thus, no need to revisited any assigned node `(i, j)`\n### Implementation\n```\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        arr = collections.deque()\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((0, i, j))\n                    \n        ans = [[-1] * n for _ in range(m)]\n        while arr:\n            val, x, y = arr.popleft() \n            if ans[x][y] != -1: continue\n            ans[x][y] = val\n            for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:\n                xx, yy = x+dx, y+dy\n                if 0 <= xx < m and 0 <= yy < n and ans[xx][yy] == -1:\n                    arr.append((val+1, xx, yy))\n        return ans\n```
['Breadth-First Search', 'Matrix', 'Python', 'Python3']