Python 3 | BFS, Set Intersection | Explanation
Explanation\n- Starting from pacific and atlantic, going back to the water, check which position they can reach\n\t- Of course, following statement should be re
### Explanation\n- Starting from pacific and atlantic, going back to the water, check which position they can reach\n\t- Of course, following statement should be reversed\n\t- > Water can only flow in four directions (up, down, left, or right) from a cell to another one with height equal or lower.\n\t- i.e. Pacific or Atlantic water can only go to water, which height is equal or higher\n- Take intersection of 2 sets to find common positions\n### Implementation\n```\nclass Solution:\n    def pacificAtlantic(self, matrix: List[List[int]]) -> List[List[int]]:\n        if not matrix: return []\n        m, n = len(matrix), len(matrix[0])\n        pacific = [(0, i) for i in range(n)] + [(i, 0) for i in range(1, m)]\n        atlantic = [(m-1, i) for i in range(n)] + [(i, n-1) for i in range(m-1)]\n        def bfs(q):\n            visited = set()\n            q = collections.deque(q)\n            while q:\n                i, j = q.popleft()\n                visited.add((i, j))\n                for ii, jj in map(lambda x: (x[0]+i, x[1]+j), [(-1, 0), (1, 0), (0, -1), (0, 1)]):\n                    if 0 <= ii < m and 0 <= jj < n and (ii, jj) not in visited and matrix[ii][jj] >= matrix[i][j]:\n                        q.append((ii, jj))\n            return visited     \n        return bfs(pacific) & bfs(atlantic)\n```
['Breadth-First Search', 'Ordered Set', 'Python', 'Python3']