Count the islands
Given a binary grid where 1 is land and 0 is water, count the islands: maximal groups of 1s connected horizontally or vertically (not diagonally). The same structure appears as "count clusters of correlated assets" in an adjacency matrix thresholded at some correlation level.
grid = [[1, 1, 0, 0, 0],
[1, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 1]]
-> 3
Return the number of islands. Aim for .
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.