JavaScript DFS
\n/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nconst pacificAtlantic = (matrix) => {\n  if (matrix.length === 0) return [];\n  \n  const pa
```\n/**\n * @param {number[][]} matrix\n * @return {number[][]}\n */\nconst pacificAtlantic = (matrix) => {\n  if (matrix.length === 0) return [];\n  \n  const pacific = [];\n  const atlantic = [];\n  const result = [];\n  \n  for (let i = 0; i < matrix.length; i++) {\n    pacific[i] = Array(matrix[0].length).fill(0);\n    atlantic[i] = Array(matrix[0].length).fill(0);\n  }\n  \n  // top and botom\n  for (let i = 0; i < matrix[0].length; i++) {\n    dfs(matrix, 0, i, Number.MIN_SAFE_INTEGER, pacific);\n    dfs(matrix, matrix.length - 1, i, Number.MIN_SAFE_INTEGER, atlantic);\n  }\n  \n  // left and right\n  for (let i = 0; i < matrix.length; i++) {\n    dfs(matrix, i, 0, Number.MIN_SAFE_INTEGER, pacific);\n    dfs(matrix, i, matrix[0].length - 1, Number.MIN_SAFE_INTEGER, atlantic);\n  }\n  \n  for (let i = 0; i < matrix.length; i++) {\n    for (let j = 0; j < matrix[0].length; j++) {\n      if (pacific[i][j] === 1 && atlantic[i][j] === 1) {\n        result.push([i, j]);\n      }\n    }\n  }\n  \n  return result;\n};\n\nfunction dfs(matrix, row, col, previous, ocean) {\n  // if we\'re looking at a valid matrix position\n  if (!isValid(matrix, row, col)) return;\n  \n  // ocean can\'t reach\n  if (matrix[row][col] < previous) return;\n\n  // the ocean was already here\n  if (ocean[row][col] === 1) return;\n  \n  ocean[row][col] = 1;\n  dfs(matrix, row + 1, col, matrix[row][col], ocean);\n  dfs(matrix, row - 1, col, matrix[row][col], ocean);\n  dfs(matrix, row, col + 1, matrix[row][col], ocean);\n  dfs(matrix, row, col - 1, matrix[row][col], ocean);\n}\n\nfunction isValid(matrix, row, col) {\n  const rowIsValid = row >= 0 && row < matrix.length;\n  const colIsValid = col >= 0 && col < matrix[0].length;\n  return rowIsValid && colIsValid;\n}\n```
['Depth-First Search', 'JavaScript']