Most Concise C++ Solution (DFS + Bit Mask)
\nclass Solution {\npublic:\n\tint dx[4] = {1, -1, 0, 0};\n\tint dy[4] = {0, 0, -1, 1};\n\n\tvector<vector<int>> ans, mask;\n\n\tvector<vector<int>> pacificAtla
```\nclass Solution {\npublic:\n\tint dx[4] = {1, -1, 0, 0};\n\tint dy[4] = {0, 0, -1, 1};\n\n\tvector<vector<int>> ans, mask;\n\n\tvector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {\n\t\tint m = heights.size(), n = heights[0].size();\n\t\tmask.resize(m, vector<int>(n, 0));\n\n\t\tfunction<void(int, int, int, int)> dfs = [&](int r, int c, int prev, int val) {\n\t\t\tif (r < 0 or c < 0 or r >= m or c >= n or ((mask[r][c] | val) == mask[r][c])) return;\n\t\t\tif (heights[r][c] < prev) return;\n\t\t\tmask[r][c] |= val;\n\t\t\tif (mask[r][c] == 3) ans.push_back({r, c});\n\t\t\tfor (int dir = 0; dir < 4; ++dir) {\n\t\t\t\tint x = r + dx[dir];\n\t\t\t\tint y = c + dy[dir];\n\t\t\t\tdfs(x, y, heights[r][c], mask[r][c]);\n\t\t\t}\n\t\t};\n\n\t\tfor (int i = 0; i < m; ++i) {\n\t\t\tdfs(i, 0, INT_MIN, 1);\n\t\t\tdfs(i, n - 1, INT_MIN, 2);\n\t\t}\n\t\tfor (int j = 0; j < n; ++j) {\n\t\t\tdfs(0, j, INT_MIN, 1);\n\t\t\tdfs(m - 1, j, INT_MIN, 2);\n\t\t}\n\t\treturn ans;\n\t}\n};\n```
['Depth-First Search', 'C', 'Bitmask']