[Python] BFS with demo figures and some similar problems to practice
The main idea is starting from water (1) and BFS entire the matrix.\n1. Find and flip all 1, and store its position to a queue. We also use a set to store visit
The main idea is starting from water (1) and BFS entire the matrix.\n1. Find and flip all 1, and store its position to a queue. We also use a set to store visited position.\n \n![image](https://assets.leetcode.com/users/images/637cf5d1-f2bf-4e32-b269-417b93a143ce_1613840238.5843472.png)\n\n\n2. BFS: Pop current position: (cur_x, cur_y) from queue then move to 4 directions [Down, Up, Right, Left] to new position: (new_x, new_y), if it has not visited yet, isWater(new) = isWater(cur) + 1\n\n![image](https://assets.leetcode.com/users/images/7234a3fe-81e5-4d81-b38e-96d1a588847f_1613841112.574654.png)\n```\nclass Solution:\n    def highestPeak(self, isWater: List[List[int]]) -> List[List[int]]:\n        rows, cols = len(isWater), len(isWater[0])        \n        visited = set()\n        queue = deque()\n        \n        for r in range(rows):\n            for c in range(cols):\n                if isWater[r][c] == 1:\n                    isWater[r][c] = 0\n                    visited.add((r, c))\n                    queue.append((r, c))\n                     \n        while queue:\n            cur_x, cur_y = queue.popleft()\n            print(cur_x, cur_y)\n            for dirr in [(1,0), (-1,0), (0,1), (0,-1)]:\n                new_x, new_y = cur_x + dirr[0], cur_y + dirr[1]\n                \n                if 0 <= new_x <= rows - 1 and 0 <= new_y <= cols - 1 and (new_x, new_y) not in visited:                        \n                        isWater[new_x][new_y] = isWater[cur_x][cur_y] + 1\n                        visited.add((new_x, new_y))\n                        queue.append((new_x, new_y))\n                        \n        return isWater\n```\n\nPractice problems: \nhttps://leetcode.com/problems/01-matrix/\nhttps://leetcode.com/problems/as-far-from-land-as-possible/\nhttps://leetcode.com/problems/rotting-oranges/\nhttps://leetcode.com/problems/shortest-path-in-binary-matrix/
[]