Shortest Bridge
Problem statement
grid contains exactly two four-directionally connected islands of 1s. Return the minimum number of 0 cells that must be changed to 1 to connect the islands.
Function
shortestBridge(grid: int[][]) → intExamples
Example 1
grid = [[0,1],[1,0]]return = 1Flipping either remaining zero joins the islands.
Constraints
2 <= grid.length, grid[0].length <= 100.- The grid contains exactly two islands.