Hi Everyone,
I appeared for Google L5 interview in October 2024. Here are the questions I was asked. Hope this will help people preparing for the same role.
Round 1:
Straight from Leetcode : Meeting Rooms III
Round 2: Have seen this in some discuss section not a direct problem from leetcode. Similar to this - https://leetcode.com/discuss/interview-question/763001/count-number-of-freshwater-lakes-in-2d-matrix
However, the constraints were different.
You are given a 2D grid grid of size m x n, where:
Each cell contains a value of either 0 or 1.
0 represents water, which can either be saltwater (connected to the infinite ocean) or freshwater (completely surrounded by land).
1 represents land.
The grid is implicitly surrounded by an infinite ocean of saltwater.
You are also given a specific point [i, j] in the grid such that grid[i][j] == 1.
This point represents a land cell within a specific piece of land.
A piece of land is defined as a connected group of 1s (connected horizontally or vertically, but not diagonally).
Your task is to determine the number of freshwater lakes within the piece of land that contains the cell [i, j].
A freshwater lake is defined as a group of 0s that is completely enclosed by the land (i.e., not connected to the infinite ocean).
Input:
grid - A 2D integer array of size m x n (1 <= m, n <= 1000):
grid[i][j] == 0 represents water.
grid[i][j] == 1 represents land.
[i, j] - A pair of integers representing a land cell's position in the grid, where grid[i][j] == 1.
Output:
An integer representing the number of freshwater lakes in the piece of land containing [i, j].
Example:
Input: grid = [
[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
[0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0]
]
point = [4, 4]
Output: 2Round 3:
Again straight from leetcode: Smallest String With Swaps
Thanks to this community, I got a lot of new problems to work on. Trying to return a small favour.