Question d’entretien chez Microsoft

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

Réponse à la question d'entretien

Utilisateur anonyme

30 mars 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.