Challenge - 5 Problems
Stack Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this stack push and pop sequence?
Consider a stack initially empty. We perform these operations in order:
push(5), push(10), pop(), push(15), pop(), pop().
What is the output of each pop operation?
push(5), push(10), pop(), push(15), pop(), pop().
What is the output of each pop operation?
DSA C
Stack operations: push(5) push(10) pop() -> ? push(15) pop() -> ? pop() -> ?
Attempts:
2 left
💡 Hint
Remember stack follows Last In First Out (LIFO). The last pushed item is popped first.
✗ Incorrect
The first pop removes 10 (last pushed), second pop removes 15, third pop removes 5.
🧠 Conceptual
intermediate1:30remaining
Which statement correctly describes the LIFO principle in stacks?
Choose the statement that best explains how the LIFO principle works in a stack.
Attempts:
2 left
💡 Hint
Think about which element is on top of the stack.
✗ Incorrect
LIFO means last in, first out, so the last element added is removed first.
🔧 Debug
advanced2:00remaining
What error occurs in this stack pop implementation?
Given this C code snippet for popping from a stack, what error will occur if the stack is empty?
int pop() {
if (top == -1) {
return stack[top];
}
return stack[top--];
}DSA C
int pop() { if (top == -1) { return stack[top]; } return stack[top--]; }
Attempts:
2 left
💡 Hint
Check what happens when top is -1 and you access stack[top].
✗ Incorrect
When top is -1, accessing stack[-1] is invalid and returns garbage or causes runtime error.
📝 Syntax
advanced1:30remaining
Which option correctly declares a stack array and top variable in C?
Choose the correct C code snippet to declare a stack of size 10 and initialize top to -1.
Attempts:
2 left
💡 Hint
Stack is an array, top starts at -1 to indicate empty stack.
✗ Incorrect
Option A correctly declares an integer array and initializes top to -1.
🚀 Application
expert2:30remaining
After these stack operations, what is the stack content?
Start with an empty stack. Perform:
push(1), push(2), push(3), pop(), push(4), pop(), push(5).
What is the final stack content from bottom to top?
push(1), push(2), push(3), pop(), push(4), pop(), push(5).
What is the final stack content from bottom to top?
Attempts:
2 left
💡 Hint
Track each push and pop carefully, remembering LIFO order.
✗ Incorrect
Pop removes 3, then pop removes 4, so stack ends with 1, 2, 5.
