Data Structures & AlgorithmsHardGATE CS · DSA

Items K, L, M, N, O are pushed onto an empty stack in this order, and a pop may happen at any time. Which pop order is NOT possible?

  1. A. L M K O N
  2. B. M K L N O
  3. C. L K M O N
  4. D. K N O M L

Correct answer: B. M K L N O

Simulate greedily: push until the needed item is on top, then pop. In M K L N O, when K must be popped, L is on top of it (pushed later and not yet popped), so K cannot come out. The other sequences pass the simulation.

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

Exams that ask this topic