Stack Class

In this exercise, you are tasked with implementing a Stack class. This class should be able to:
  1. Push an item onto the stack (push() method).
  1. Pop an item from the stack (pop() method) - should remove and return the item.
  1. Check if the stack is empty (is_empty() method) - should return a boolean.
Additionally, the underlying data structure that stores the stack items (i.e., a Python list) must be private to the Stack class.
Input
Output
s = Stack(); s.push(1); s.push(2); s.push(3); print(s.pop()); print(s.is_empty()); print(s.pop()); print(s.pop()); print(s.is_empty())
3 False 2 1 True
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue