It's a variation of the famous problem of Number of Islands. I want to know the algorithm thinking approach(hint). If I want to connect all the islands given that island can be connected in all 8 directions not in only 4 directions. Then how should I approach this problem?
Example
Given
[[1 1 0 0 0]
[0 1 0 0 1]
[1 0 0 1 1]
[0 0 0 0 0]
[1 0 1 0 1]]
the expected output is 2
:
[[1 1 0 0 0]
[0 1 0 0 1]
[1 0 0 1 1]
[0 2 0 2 0]
[1 0 1 0 1]]