Implement Stack Using Two Queues
Problem statement
Implement a last-in-first-out stack using exactly two FIFO queues.
Process commands:
push x: push x and append"null".pop: remove and append the top integer.top: append the top integer without removing it.empty: append"true"or"false".
Design push and top to run in O(1).
Function
processStackUsingQueues(operations: String[]) → String[]Examples
Example 1
operations = ["push 1","push 2","top","pop","empty"]return = ["null","null","2","2","false"]Two is the most recently pushed value.
Constraints
1 <= operations.length <= 10^4.- Pop and top are called only on a nonempty stack.