GATE Computer ScienceVery hardGATE CSE · ISRO

The integers 1, 2, 3, 4, 5, 6 are pushed in this order onto a stack; pops can be interleaved with pushes at any time and every element is eventually popped. How many of the possible output (pop) sequences begin with 4 and have 6 popped before 2?

  1. A. 5
  2. B. 7
  3. C. 4
  4. D. 10

Correct answer: A. 5

Brute force over all 720 permutations, keeping only stack-realizable ones with first element 4 and 6 before 2, gives 5.

More Programming and Data Structures (GATE) questions

Exams that ask this topic