Skip to main contentSkip to solution

Assume P, D, Q, R is the input sequence for a STACK.

Arrange the given operation to get the output as shown in the STACK below:

STACK
R
Q
P

(A) POP(D)

(B) PUSH(P)

(C) PUSH(D)

(D) PUSH(R)

(E) PUSH(Q)

Solution

✅ Correct Option: 2

Input order is P, D, Q, R, and the final stack must have P at the bottom, then Q, then R on top. D must be pushed and then removed, so it never stays in the stack.

OperationStack (bottom to top)
(B) PUSH(P)P
(C) PUSH(D)P, D
(A) POP(D)P
(E) PUSH(Q)P, Q
(D) PUSH(R)P, Q, R

The stack ends as P, Q, R from bottom to top, which matches the given figure with R on top.


Option 3: POP is attempted when only P is in the stack, so it would remove P instead of D.

Option 4: the order C, B pushes D before P, which breaks the input sequence P, D, Q, R.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question