Challenge - 5 Problems
Stack Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this Rust stack simulation?
Consider a stack where we push 1, then 2, then 3, and then pop once. What is the printed stack from top to bottom?
DSA Rust
let mut stack = Vec::new(); stack.push(1); stack.push(2); stack.push(3); stack.pop(); println!("{:?}", stack);
Attempts:
2 left
💡 Hint
Remember that pop removes the last pushed item.
✗ Incorrect
The stack pushes 1, 2, 3 in order. Pop removes 3, so stack has 1 and 2 left, printed as [1, 2].
🧠 Conceptual
intermediateWhich operation follows the LIFO principle in a stack?
Choose the operation that correctly follows the Last In First Out principle in a stack.
Attempts:
2 left
💡 Hint
LIFO means the last item added is the first to be removed.
✗ Incorrect
Stacks remove the most recently added element first, which is the last element pushed.
🔧 Debug
advancedWhat error does this Rust stack code produce?
Analyze the code below and identify the error it causes when run.
DSA Rust
let mut stack = Vec::new();
stack.push(10);
stack.pop();
stack.pop();Attempts:
2 left
💡 Hint
Pop returns an Option; popping empty returns None but does not panic.
✗ Incorrect
Calling pop on an empty vector returns None safely without panic or error.
🚀 Application
advancedWhat is the stack content after these operations?
Given an empty stack, perform these operations in order: push 5, push 10, pop, push 7, push 3, pop. What is the stack content from top to bottom?
Attempts:
2 left
💡 Hint
Pop removes the last pushed item each time.
✗ Incorrect
Operations:
- push 5: stack 5
- push 10: stack 10,5
- pop: removes 10, stack 5
- push 7: stack 7,5
- push 3: stack 3,7,5
- pop: removes 3, stack 7,5
So top to bottom: 7 -> 5 -> null
❓ Predict Output
expertWhat is the output of this Rust stack simulation with multiple pops?
Analyze the code and determine the final printed stack content.
DSA Rust
let mut stack = Vec::new(); stack.push(2); stack.push(4); stack.push(6); stack.pop(); stack.push(8); stack.pop(); stack.pop(); println!("{:?}", stack);
Attempts:
2 left
💡 Hint
Track each push and pop carefully in order.
✗ Incorrect
Operations:
- push 2: [2]
- push 4: [2,4]
- push 6: [2,4,6]
- pop: removes 6 -> [2,4]
- push 8: [2,4,8]
- pop: removes 8 -> [2,4]
- pop: removes 4 -> [2]
Final stack: [2]
