""" 0232.1 - Solution 1 - Two Stack Approach """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class MyQueue:
"""Queue implemented using two stacks."""
def __init__(self):
"""Initialize two stacks: input for push, output for pop/peek."""
self.input_stack = []
self.output_stack = []
def push(self, x: int) -> None:
"""Push element x to the back of the queue."""
self.input_stack.append(x)
def pop(self) -> int:
"""Remove the element from the front of the queue and return it."""
self.peek()
return self.output_stack.pop()
def peek(self) -> int:
"""Return the element at the front of the queue."""
if not self.output_stack:
while self.input_stack:
self.output_stack.append(self.input_stack.pop())
return self.output_stack[-1]
def empty(self) -> bool:
"""Return True if the queue is empty, False otherwise."""
return not self.input_stack and not self.output_stack
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
q = MyQueue()
q.push(1)
q.push(2)
print(q.peek()) # 1
print(q.pop()) # 1
print(q.empty()) # False
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()