Implement Queue Using Stacks (LC #232) appears in Meta interviews. Use stacks: input and output. On push, add to input. On pop or peek, if output is empty, transfer all elements from input to output (reversing order). Then pop or peek from output. Each element is moved at most twice (in once, out once), so amortized per operation. Space is . The reverse operation converts LIFO to FIFO. Meta asks this in discussions about system design and message queues.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/meta-interview-prep/stacks-queues/implement-queue-using-stacks
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████