At the beginning, each cell will be “invisible”.
I will go through the cells until you meet the “invisible” black cell. Every white cell that you get to this point
As soon as you click on the black cell, you “deploy” it in all directions, if possible (similar to “floodfilling”). You expand as much as you can, and mark all visited cells as “visited”. After you have done this, you will calculate how many black cells you have infected, and you know how big the group is. After finding the group, you proceed to the next "invisible" black cell.
phimuemue
source share