My initial pseudocode (idk if it would've fully worked because I didn't implement it due to how gnarly and complicated I imagine the implementation will be - there are probably some pesky edge cases I'm missing):
Go through all cells and set any that aren't connected to 0.
Go through all cells and keep track of counts (while traversing, multiply by -1 once you've left a cell so that you know not to double count if you need to come back that way).
Return the max count
Go through all cells and keep track of the regions that don't have at least one 0 connected to them.
Go through all cells and figure out which regions connect
Return the Max(Max of the connected regions vs (Max of the regions that connect to at least one 0 + 1))
This is definitely not optimized code, but I think it would be easiest to write and fastest to implement this way.
The official solution was actually somewhat similar (at least for the beginning). I was basically doing a convoluted flood fill, which is what the official solution recommended. After the flood fill, the official solution compresses regions to single nodes for time efficiency, which is something I hadn't thought of.
Attempt 2.0
I attempted to try this problem again from scratch ~a month after first trying it and ended up writing a solution that was almost the exact same as the official one w/o even realizing it. Either I'm getting good enough that I'm starting to think on the right wavelength, or there were traces of the right solution in my memory. It's definitely more the latter but hopefully a mix of both.
This is a near-complete solution. It's only missing the last ~20 lines of code needed to find the result for 2 numbers (I've figured out single and compression).