Loading...
So basically just steal this code go brrr and remove the last 4 checks (since we dont want diagonals).
https://www.geeksforgeeks.org/find-the-number-of-islands-set-2-using-disjoint-set/?ref=rp