Challenge - 5 Problems
Stack Push Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output after pushing elements on a stack?
Consider the following Python code that uses a list as a stack. What will be the printed output after all push operations?
DSA Python
stack = [] stack.append(5) stack.append(10) stack.append(15) print(stack)
Attempts:
2 left
💡 Hint
Remember that append adds elements to the end of the list.
✗ Incorrect
The append method adds elements to the end of the list, so the stack will be [5, 10, 15].
❓ Predict Output
intermediate2:00remaining
What is the top element after pushing on stack?
After pushing elements 3, 7, and 9 on an empty stack, what is the top element of the stack?
DSA Python
stack = [] stack.append(3) stack.append(7) stack.append(9) top = stack[-1] print(top)
Attempts:
2 left
💡 Hint
The top element is the last one pushed.
✗ Incorrect
The last element pushed is 9, so stack[-1] is 9.
🔧 Debug
advanced2:00remaining
Identify the error in this push operation code
What error will this code produce when trying to push an element onto the stack?
DSA Python
stack = [] stack.push(4) print(stack)
Attempts:
2 left
💡 Hint
Check the method name for adding elements to a list.
✗ Incorrect
Python lists use append() to add elements, not push(). Using push() causes AttributeError.
❓ Predict Output
advanced2:00remaining
What is the stack content after multiple push operations?
Given this code, what is the final stack content printed?
DSA Python
stack = [1, 2] stack.append(3) stack.append(4) stack.append(5) print(stack)
Attempts:
2 left
💡 Hint
Appending adds elements to the end of the list.
✗ Incorrect
Appending adds elements at the end, so the stack grows as [1, 2, 3, 4, 5].
🧠 Conceptual
expert2:00remaining
What is the time complexity of the push operation on a stack implemented with a Python list?
Choose the correct time complexity for the push operation (adding an element) on a stack implemented using a Python list with append().
Attempts:
2 left
💡 Hint
Appending to the end of a Python list is usually very fast.
✗ Incorrect
Python list append() runs in average constant time O(1) because it adds element at the end.