PIXELBANKv8.2.1
Menu

Largest Connected Region

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

  • 1rows,cols1001 \leq rows, cols \leq 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

Test Results

0/0
Run code to see test results.