📘
Largest Connected Region
MediumUnion-Find, Optimization
Problem Statement
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).
Applications
- Finding dominant objects in a scene
- Noise filtering (removing small components)
- Main subject detection
Constraints
- 1≤rows,cols≤100
- Grid contains only 0s and 1s
Example:
Input:
grid = [[1, 1, 0, 0], [1, 1, 0, 0], [0, 0, 1, 1], [0, 0, 1, 1]]
Output:
4
Reasoning:
Two regions of size 4 each. Return 4.
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.