Given a 2D array of 1's and 0's (black and white cells) find blocks of white cells of size 1xT or Tx1 where T >= 1. Any block should not be a subset of a larger block. Return the number of these blocks.
This is an example solution of a 5x3 grid. There should be 8 blocks. Block
y:1, x:0 is not a block because it would be a subset of a bigger block
What I've tried so far
I've developed a pretty inefficient solution where I iterate through all white cells and for each one get a vertical and horizontal block. Then only accept either block if it isn't a subset of an already accepted block.
The most time complex operation in my code is checking whether a block is a subset of another accepted block.
What would be a more efficient solution to this problem?
Is there a data structure that would help me with this?