Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Using the pancake operation (reverse any prefix of length at least 2), what is the minimum number of operations to sort the array [3, 1, 2] into increasing order? Search all arrangements (breadth-first).

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

Correct answer: D. 2

A breadth-first search over all permutations gives the minimum; here two prefix reversals suffice, which the search confirms.

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

Exams that ask this topic