Need help in graph problem - Solved with approach defined - Google Kickstart Round H, Diagonal Puzzle

yeah, I mean if current cell is white, we can flip its colour either by flipping left or right diagonal. Wht do you meant, by retain the colour in two ways both or none?

I meant that if we flip both the diagonals or none of the diagonals the colour of the cell doesn’t change.

correct,

so we first pick a white cell and call dfs on one of its diagonals.

calling dfs here means making the diagonal visited on every cell in the diagonal

and if any cell is already black we call dfs on the other diagonal.

to retain its colour

B W B
W B B
B B B

If we pick this diagonal(chose 1,0). meaning, B(2,1) is already black. So we need to call dfs (on one diagonal, here we can’t chose left upwards diagonal as it is alrady visited for this black cell)here to retain its colour, Is that what do you meant?

yes

Thankyou very much for the help, really appreciated your help @satwik_bhv1

1 Like

Thankyou all, I have updated the Solution appraoch above in the problem, if anyone interested.

1 Like

In fact I should thank you for posting such a wonderful question.

1 Like