Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: A stack-sortable check is applied to the permutation [3, 1, 2]: elements are pushed in order and popped whenever the top equals the next expected value (1, 2, 3, …). Is the stack empty at the end? Answer 1 for yes, 0 for no.

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

Correct answer: B. 1

Push 3, then 1 is pushed and popped, then 2 is pushed and popped, which releases 3 from the stack. The stack is empty at the end, so the permutation is stack-sortable.

More Coding Interview Problems questions

Exams that ask this topic