Pergunta de entrevista da empresa Microsoft

In any language you want, write a queue using only stacks.

Resposta da entrevista

Sigiloso

30 de mar. de 2025

Create 2 stacks. On "append" add to the first one. On "remove" remove from the second one, unless it is empty, in which case move all items from the first stack to the second (flipping their order) and then remove from the second one. This keeps the amortized complexity identical to a regular queue.