Question Bank

Stack and Queue Fundamentals

Difficulty: Easy

Four short prompts on LIFO vs FIFO behavior, balanced parentheses, and a bug hunt in a circular queue. Good warm-up before monotonic-stack drills.

Question Bank
/

Stack and Queue Fundamentals

Stack and Queue Fundamentals

Four short prompts on LIFO vs FIFO behavior, balanced parentheses, and a bug hunt in a circular queue. Good warm-up before monotonic-stack drills.

Question Bank
Easy
JavaScript
4 questions
stack
queue
data-structures
fundamentals

957 views

8

What does this snippet print and why? Identify which structure is LIFO and which is FIFO.

Examples

Example 1:

Input: push 1, 2, 3 then pop twice on a stack; push 1, 2, 3 then shift twice on a queue
Output: stack pops 3, 2 (LIFO); queue shifts 1, 2 (FIFO)
Explanation: Stacks return the most recently pushed element. Queues return the oldest. Note Array.prototype.shift is O(n); use a deque or head-index for true O(1) FIFO.