Consider a stack that allows push and pop operations in the usual way.
Palo Alto Networks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Consider a stack that allows push and pop operations in the usual way. Suppose you record the numbers popped out. Which of the following operations can be obtained using stack operations assuming that the input is the sequence 11,12,13,14,15?
Assume that push and pop operations are independent.
Select any one of the following options
Show answer & explanation
Pushing 11, 12, 13 and popping 13, then pushing 14 and popping 14, then pushing 15 and popping 15 leaves 12 and 11 on the stack, which must pop in order 12, then 11.
Step-by-step Derivation:
Step 1: Push 11, Push 12, Push 13.
Step 2: Pop 13 (output: 13).
Step 3: Push 14, Pop 14 (output: 13, 14).
Step 4: Push 15, Pop 15 (output: 13, 14, 15).
Step 5: Pop remaining stack elements: 12, then 11.
Step 6: Resulting permutation is 13, 14, 15, 12, 11.