Queue built from two stacks
Write a class StackQueue: a first-in, first-out queue of integers whose only storage is stacks, that is, Python lists used through append, pop() from the end, [-1] and len.
push(x)addsxat the back of the queue.pop()removes the value at the front and returns it.peek()returns the value at the front without removing it.empty()returns whether the queue holds no values.
pop and peek are never called on an empty queue. Every operation must take O(1) amortized time.
The tests call the provided run_queue(ops): it applies each operation in order and returns the list of results (None for push, shown as null).
Besides the tests, one large input (3,000 queued values, 3,000 pops) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
run_queue([["push",1],["push",2],["peek"],["pop"],["empty"],["pop"],["empty"]])→[null,null,1,1,false,2,true]run_queue([["push",5],["push",6],["pop"],["push",7],["push",8],["pop"],["pop"],["peek"]])→[null,null,5,null,null,6,7,8]