Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

A pancake flip reverses a prefix of length at least 2. What is the minimum number of prefix flips needed to sort [3, 1, 2] into increasing order?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Breadth-first search over arrangements gives the minimum flips. Reversing a prefix of length 1 changes nothing, and a single flip is not always enough.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic