Hi Folks,
Currently SSE @ Walmart
YOE: 6.5
Recently appeared for Phone Screening round for Coupang (Rocket Growth Team) Bangalore.
Time: 60min
Given a grid[][] containing 0s and 1s, where '0' represents water and '1' represents the land. Given that an island is a group of land (1s) surrounded by water (0s) on all sides.
The task is to find the distance between the two closest islands such that:
Input: grid =
{{1, 1, 0, 1, 1},
{1, 1, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 1, 1, 1}}
Output: 1
Explanation: There are three islands present in the grid.
Nearest pair of islands have only 1 zero (bolded in input grid) in between them.
Input: grid =
{{1, 0, 0, 0, 1},
{1, 1, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 1, 1, 1}}
Output: 2
Explanation: There are three islands present in the grid.
Nearest pair of islands have 2 zeroes in between them (depicted by bold 0 in input grid).
In this case there are multiple pair of islands having a distance of 2 between them.
#coupang #tps #blr