Multiple choice

The following sequence of operations is performed on a stack push (1), push (2), pop, push(1), push(2), pop, pop, pop, push(2), pop. The sequence of the popped out values is

  1. 2, 2, 1, 1, 2

  2. 2, 2, 1, 2, 2

  3. 2, 1, 2, 2, 1

  4. 2, 1, 2, 2, 2

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Sequence: push(1) [1], push(2) [1,2], pop [1](val 2), push(1) [1,1], push(2) [1,1,2], pop [1,1](val 2), pop [1](val 1), pop [](val 1), push(2) [2], pop [](val 2). Popped values: 2, 2, 1, 1, 2.