Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many different output orders can a stack produce from the input 1, 2, 3, 4 pushed in order?

  1. A. 24
  2. B. 16
  3. C. 10
  4. D. 14

Correct answer: D. 14

The number of stack-generated permutations of n items is the Catalan number C_n, and C_4 = 14. All 24 permutations are not reachable with a single stack.

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

Exams that ask this topic