Consider a stack with the following elements: 5, 4, 3, 2 where the top element…

Consider a stack with the following elements: 5, 4, 3, 2 where the top element is 2. You need to transform the stack into the following state: 6, 5, 4, 3, 2 with 6 as the new top element. The only operations allowed are push() and pop(). Which sequence of operations achieves the desired stack configuration?

  1. A.

     push(pop()), push(6), push(pop())

  2. B.

     push(pop()), push(6)

  3. C.

    push(pop()), push(pop()), push(6)

  4. D.

     push(6)

Attempted by 71 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…