5. You have a stack with elements [5, 10, 15, 20] (5 at bottom, 20 at top). You perform two pop operations, then push 25, then pop once. What is the final stack content?
hard
A. [5, 10, 25]
B. [5, 10, 15]
C. [5, 10]
D. [5, 10, 15, 25]
Solution
Step 1: Perform two pop operations
Initial stack: bottom 5,10,15, top 20. First pop removes 20, second pop removes 15. Stack now: [5, 10].
Step 2: Push 25 and pop once
Push 25: stack becomes [5, 10, 25]. Pop removes 25, stack returns to [5, 10].
Step 3: Verify final stack
Final stack is [5, 10].
Final Answer:
[5, 10] -> Option C
Quick Check:
Pop removes top, push adds top [OK]
Hint: Track pushes and pops stepwise to find final stack [OK]
Common Mistakes:
Forgetting last pop removes pushed element
Mixing order of elements
Assuming push adds at bottom
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.