maxArea
to keep track of the maximum island size found.area
, with the group ID as the key and the component size as the value.0
, check its 4 neighboring cells.maxArea
if the potential island size is larger than the current maxArea
.0
is flipped, set maxArea
to the size of the largest component found during the DFS.maxArea
as the final answer.