Oversized Pancake Flipper - Google Code Jam

Lorenzo Mele on April 10, 2017

Google Code Jam If you're a programmer and you don't know Google Code Jam, you should definitely go and check that. It's basically a c... [Read Full]
markdown guide

Wow! Nice solution. I have been thinking about it for a while and I still have two open quiestions:

  • Does it work in any case?
  • Does it find the optimal solution (minimum flips)?

The first one seems to be true (at least the cases tested) but I can't see why. I am not so sure about the second one.
Can you give me any clue about them?

Due to my background I would go for a graph search based solution. The nodes of the graph are the state of the row of pancakes and the neighbors of a node are those states reachable by a flip action.
It is not the fastest one, but it is exhaustive and the solution is optimal.

  • Does it work in any case?

I cannot show you the mathematical explanation but I have some hints.
Let's take the example of the post but reversed:


These are exactly the same flips made above.

I think the key point here is that you should never touch happy pancakes, unless forced to do so because of a nearest unhappy one.


This is not fair !!
I was trying to solve it with other ways.
solution is so simple that its raising Questions..?

does its a complete solution ?

  • theoretically I can see its not optimal in finding of minimum flips
  • theoretically with complex and long input(where cursor should move backward as well) its incomplete solution !

How many rounds do I need to pass if i want to have a job in google🤔


I don't know... I think you should be notable (anything that means) :)


Huh, I can't believe the solution is so simple in the end!
I tried to solve it using XOR and discrete mathematics :(
Thanks for the post!

BTW you got a typo ("at the and")


Yes, that was my thought too!

(thanks for the typo ;) )

code of conduct - report abuse