Google Onsite Interview US

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-09-14Added By Anonymous
Source: Link

Company: Google
Role: unknown
Interview Stage: Onsite
Location: US
Year: unknown

Original Post Content:

Count the number of lakes in an island

Given a large grid of m * n and an island coordinate within the grid. You need to calculate the number of lakes within the island from the coordinate given and there can be multiple islands in the grid surrounded by a large ocean. You can assume that there is ocean outside the grid as well.

A lot of data was left ambiguous. On asking questions, it came to be known that there can be zero or more lakes within an island. If a lake within an island is connected to an ocean then it should not be counted.

It was a graph traversal question but needed some optimizations and the question was too long to go over so the first 15 minutes are spent in asking clarifying questions and understanding the problem. The main constraint was that the grid is too large and we should be able to differentiate the lake from the ocean.

Comments