Problem statement
Imagine you’re working on a language which only supports Stack, but you need a Queue functionality to fulfill the requirement. Design a queue that supports standard operations using stacks.
Brief idea (EN)
Use two stacks: in and out.
enqueue(x):in.push(x)dequeue()/front(): ifoutis empty, move all items fromintoout; then pop/peek fromout.empty(): true if both stacks are empty.
Amortized O(1) per operation, worst-case O(n) when transferring.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Microsoft Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.