FastPrepPacific Atlantic Water Flow
Problems/Pacific Atlantic Water Flow

Pacific Atlantic Water Flow

Airbnb logoAirbnb● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a post about an Airbnb campus hiring process, published in May 2023. The post does not give the role or the interview date.

This task came up in the first technical round, right after an introduction. The candidate had to code a complete solution, talk through it and state how fast it runs. The post names the task only through a link to a standard version: rain on a grid of heights draining to two oceans. We wrote it in that usual form. We also ask for the cells sorted by row and then by column, and the limits and the examples are our own.

Our version is about 85% the same as the reported question.

An island is drawn as an m x n grid of cells, where heights[r][c] is the height of the cell in row r and column c. The Pacific Ocean touches the island's top and left edges, and the Atlantic Ocean touches its bottom and right edges.

Rain falls on every cell. Water on a cell can move to a neighbor cell above, below, to the left or to the right when the neighbor's height is less than or equal to the current cell's height. Water on a cell in the top row or the left column can also flow straight into the Pacific, and water on a cell in the bottom row or the right column can flow straight into the Atlantic.

Return the coordinates [r, c] of every cell from which water can reach both oceans. Sort the list by row, and by column within the same row.

Function

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

Examples

Example 1

heights = [[1,2,3],[8,9,4],[7,6,5]]return = [[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
heights
012012318942765

Cell [0,0] (height 1) touches the Pacific, but both of its neighbors (2 and 8) are higher, so its water cannot go anywhere else and never reaches the Atlantic. Cell [0,1] (height 2) can only flow left into [0,0], so it is stuck the same way. Every other cell works. For example, the top right cell [0,2] touches both oceans, cell [2,2] (height 5) flows to 4 and then 3 at the top edge, and the middle cell (height 9) can flow left to 8 on the left edge or right to 4 on the right edge.

Example 2

heights = [[4,1,3],[2,0,2],[3,1,4]]return = [[0,2],[2,0]]
heights
012041312022314

The corners [0,2] and [2,0] each touch both oceans. The middle cell (height 0) touches no ocean and is lower than all four of its neighbors, so water that enters it stays there. Each of the four cells in the middle of an edge (heights 1, 2, 2 and 1) touches one ocean, and its only neighbor that is not higher is the middle cell. From [0,0] (height 4), water can reach [0,1], [1,0] and the middle cell, and none of them touches the Atlantic. In the same way, water from [2,2] never reaches the Pacific.

Example 3

heights = [[2,7,4]]return = [[0,0],[0,1],[0,2]]
heights
0120274

With a single row, every cell is on the top edge and on the bottom edge at the same time, so every cell touches both oceans.

Constraints

  • m == heights.length
  • n == heights[r].length
  • 1 <= m, n <= 200
  • 0 <= heights[r][c] <= 105

More Airbnb Phone Screen questions

  • Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
  • Text JustificationPHONE SCREEN · Seen Nov 2026
  • Decode and Store StringsPHONE SCREEN · Seen Oct 2026
  • Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
  • Smallest Common RegionPHONE SCREEN · Seen Aug 2026
  • Longest Chain BookingPHONE SCREEN · Seen Aug 2026
  • Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
  • Parse Query StringPHONE SCREEN · Seen May 2026
  • Cheapest Flight with Its PathOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022

Similar questions at other companies

  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Count Islands with Eight-Direction AdjacencyAmazon · PHONE SCREEN
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Count the IslandsAdobe · PHONE SCREENAdobe interview questions
  • Maximum Area of IslandSkydio · PHONE SCREENSkydio interview questions
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences

Airbnb interview experiences

  • Airbnb SWE OA: Four-Level Banking System: 1 Experience
  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public List<List<Integer>> pacificAtlantic(int[][] heights) {
      // Write your code here.
    }
}
Checking account…