Help needed in Magical Flips

I was trying to solve Magical Flips problem in today’s contest. But unable to find the solve it. Can someone please help me in debugging it solution.
my solution