Google Interview

You have a 3x3 grid. In each cell you can have two colors, white or black. At the beginning, the matrix has some cells painted white and others black.

If you change a color cell, that is, grid [i] [j] the cells grid [i-1] [j], grid [i + 1] [j], grid [i] [j-1] and grid [ i] [j+ 1] also change (if these positions do not leave the 3x3 grid), that is, if they were white, they change to black.

Return, the minimum number of cells you have to flip for the 3x3 grid to be totally white. If you can do this, return -1!

For exmaple: