You are given an R x C binary grid where:
1
represents land
0
represents water
The grid contains exactly two 4-directionally connected islands (connected via up/down/left/right). You may flip water cells (0) into land (1).
Return the minimum number of water cells to flip so that the two islands become connected (i.e., there exists a 4-directional path of 1s between them).
grid
: 2D array of integers (
0
or
1
)
1 <= R, C <= 200
If flipping a single 0 cell can connect the islands, return 1.