Loading...
After performing connected component analysis, we often want to find the largest object (region with most pixels).
Given a 2D binary grid, use Union-Find to identify all connected foreground regions and return the size of the largest region (count of 1s in that region).
grid = [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]
4
Two regions of size 4 each. Return 4.