Python lists use append() to add elements, not push().
Step 2: Identify the error
Calling stack.push(5) causes AttributeError because 'push' is not a list method.
Final Answer:
'push' method does not exist for list -> Option C
Quick Check:
Use append() for stack push in list [OK]
Hint: Use append() to push on list, not push() [OK]
Common Mistakes:
Assuming push() is a list method
Thinking pop() is missing
Believing stack can't be made with list
5. You need to design a system that keeps track of the top 3 highest scores in a game, updating efficiently as new scores arrive. Which data structure is the best choice?
hard
A. Min-Heap of size 3
B. Max-Heap of all scores
C. Linked List sorted ascending
D. Queue storing last 3 scores
Solution
Step 1: Understand the requirement for top 3 scores
We want to keep only the highest 3 scores updated efficiently as new scores come in.
Step 2: Choose data structure for efficient top-k tracking
A min-heap of size 3 keeps the smallest of the top scores at the root. When a new score arrives, compare with root; if higher, replace root and heapify. This keeps top 3 efficiently.
Final Answer:
Min-Heap of size 3 -> Option A
Quick Check:
Top-k tracking = Min-Heap size k [OK]
Hint: Use min-heap of size k to track top k items efficiently [OK]
Common Mistakes:
Using max-heap of all scores wastes memory
Using linked list is slow for updates
Queue stores last scores, not top scores
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.