β back to unit
Medium
# stacks medium
Never Pop an Empty Pile
The rookie robot keeps grabbing at an empty dispenser β teach it manners! π€
You get commands (add:x or take), but this time a take might arrive when the pile is empty. For each such doomed take, print empty! on its own line. At the end print how many plates remain.
Example:
Input: commands = ["take", "add:a", "take", "take"]
Output:
empty!
empty!
0
The first take has nothing to grab (empty!). add:a puts one plate on, and the second take removes it fine. The third take finds the pile empty again (empty!) β leaving 0 plates.
π‘ need a hint?
stk-never-pop-empty.pyπ given lines are locked β write your code in between
loading...