FastPrepWater Cells Adjacent to Land
Problems/Water Cells Adjacent to Land

Water Cells Adjacent to Land

Google logoGoogle● EasyINTERNONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes identifying water cells next to islands but omits the follow-up's neighbor and output rules. Eight directions, all islands, and unique ordered coordinates are practice assumptions. Approximate source match: 60%.

You are given a non-empty rectangular grid called grid. Each cell is either land (1) or water (0).

Find every water cell that touches a land cell. Cells can touch along a side or at a corner. All eight neighboring directions count. Include land from every island, and only consider cells inside the grid.

Return the water cells as an array of [row, column] pairs:

  • Row and column numbers start at 0.
  • Include each water cell only once, even if it touches several land cells.
  • Sort by row from smallest to largest. Within the same row, sort by column from smallest to largest.

Return an empty array if no water cells touch land. Do not change grid.

Function

waterCellsAdjacentToLand(grid: int[][]) → int[][]

Examples

Example 1

grid = [[1,0,0],[0,0,1],[0,0,0]]return = [[0,1],[0,2],[1,0],[1,1],[2,1],[2,2]]
grid
012010010012000
→
return
01001102210311421522

Six water cells touch land. Cell [2, 0] does not. Cells [0, 2] and [2, 2] touch the land at [1, 2].

Example 2

grid = [[1,0],[0,0]]return = [[0,1],[1,0],[1,1]]
grid
01010100
→
return
01001110211

Cell [1, 1] qualifies through diagonal contact. Every coordinate appears once.

Example 3

grid = [[0,0,0]]return = []
grid
0120000

The grid has no land, so no water cell qualifies.

Constraints

  • 1 <= grid.length <= 50
  • 1 <= grid[0].length <= 50
  • Every row has the same length.
  • Every cell is 0 or 1.

More Google Onsite Interview questions

  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Filesystem Entity Total SizeONSITE INTERVIEW · Seen Nov 2026
  • Longest Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
  • Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
  • Validate a Two-Color ChessboardAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
  • Trace of a Square MatrixAkuna Capital · PHONE SCREEN · ONSITE INTERVIEWAkuna Capital interview questions
  • Unique Rows of a Binary MatrixExpedia · ONSITE INTERVIEWExpedia interview questions
  • Iterate Ragged Integer Lists VerticallyZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions

Interview reports that mention this question

  • Google Intern Coding and OOP: 19 Experiences (Part 5 of 8)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] waterCellsAdjacentToLand(int[][] grid) {
        // write your code here
    }
}
Checking account…