Imagine you have a map of a region divided into a grid. Each cell in the grid can either be land (represented by 1) or water (represented by 0).
In this region, there are two separate islands. An island is defined as a group of land cells that are connected horizontally or vertically and are not connected to any other land cells.
Your task is to connect these two islands by converting water cells into land cells. Determine the minimum number of water cells you need to convert to land cells to connect the two islands into one larger island.
Input:
Map is denoted as n x n grid. where n is grid.length.
grid[i][j] == 0 or 1.
There are exactly two islands in grid.
[[0,1,0]
[0,0,0]
[0,0,1]]
[[1,1,1,1,1]
[1,0,0,0,1],
1,0,1,0,1]
[1,0,0,0,1]
[1,1,1,1,1]]