FastPrepPacific Atlantic Water Flow
Problems/Pacific Atlantic Water Flow

Pacific Atlantic Water Flow

Anduril logoAnduril● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Anduril full-time phone screen. The report names the well-known Pacific Atlantic Water Flow problem. We kept that problem as it is. We only added a fixed order for the coordinates in the answer.

You are given an m x n matrix heights, where heights[r][c] is the height of cell (r, c). Rainwater may flow from a cell to a four-directionally adjacent cell only when the neighboring cell's height is less than or equal to the current cell's height.

The Pacific Ocean touches the top and left edges of the matrix. The Atlantic Ocean touches the bottom and right edges. Return every coordinate from which water can flow to both oceans. Return each coordinate once in ascending row order, breaking row ties by ascending column.

Function

pacificAtlantic(heights: int[][]) → List<List<Integer>>

Examples

Example 1

heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]return = [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]
heights
01234012235132344224531367145451124

Each returned cell has a path of non-increasing heights to the Pacific edge and another to the Atlantic edge. The cells are listed by row, then by column.

Example 2

heights = [[1]]return = [[0,0]]
heights
001

The only cell touches all four matrix edges, so it can reach both oceans.

Constraints

  • 1 <= m, n <= 200.
  • 0 <= heights[r][c] <= 100000.
  • Movement is allowed only up, down, left, or right.
  • The returned coordinates must be lexicographically ordered by row and then column.

More Anduril interview questions

  • Choose the Front Football TeamPHONE SCREEN · Seen May 2026
  • Maximum Visible DronesPHONE SCREEN · Seen Jun 2024
  • Build a Sorted Circular Singly Linked ListPHONE SCREEN · Seen Feb 2024
  • Sparse Vector Dot ProductPHONE SCREEN · Seen Apr 2021
  • Add Word and Suffix SearchONSITE INTERVIEW · Seen Aug 2026
  • Binary Tree Preorder TraversalONSITE INTERVIEW · Seen Aug 2026
  • Operator-First Array CalculatorONSITE INTERVIEW · Seen Aug 2026
  • Daily TemperaturesONSITE INTERVIEW · Seen Jun 2024
  • Highlighted Context WindowsONSITE INTERVIEW · Seen Jun 2024

Similar questions at other companies

  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Maximum Area of IslandSkydio · PHONE SCREENSkydio interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Max Area of IslandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions
  • Max Area of IslandBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Area of IslandSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
All Anduril interview questionsSee Anduril hiring insights
Saved
class Solution {
    public List<List<Integer>> pacificAtlantic(int[][] heights) {
        // Write your code here.
    }
}
Checking account…