Cody

Problem 42498. Pancake sorting - minimum flips.

Sort a stack of pancakes by flipping them using spatula.

  • There are N pancakes with diameters 1:N.
  • Spatula can be inserted anywhere in the stack and used to flip all the pancakes above.
  • Sort pancakes in increasing order.
  • Return a vector of places where spatula was inserted.
  • Minimize number of flips, your score will depend on the number of flips in the last few tests.
  • References: math.illinois.edu, wikipedia.

Example (horizontal view):

Initial stack:  6 4 2 5 3 1,         ("," indicates position of spatula)
first flip:     1 3 5,2 4 6
second:         5 3 1 2 4,6
...             4 2 1 3,5 6
                3 1 2,4 5 6
                2 1,3 4 5 6
sorted!         1 2 3 4 5 6
positions of spatula from the begining: 6 3 5 4 3 2

Solution Stats

73.81% Correct | 26.19% Incorrect
Last solution submitted on Sep 18, 2019

Problem Comments

Problem Recent Solvers15

Suggested Problems

More from this Author47

Problem Tags