Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div 2

How many permutations of 1..5 can be produced by pushing 1, 2, 3, 4, 5 in order onto a stack and popping at any moment?

  1. A. 120
  2. B. 32
  3. C. 52
  4. D. 42

Correct answer: D. 42

Stack-producible permutations are counted by the Catalan number C₅ = 42. The 120 permutations of five items include many the stack cannot make.

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

Exams that ask this topic