A friend had a phone interview for a job in a company that I won’t name - It’s Microsoft. One of the questions was about describing how he would write a stack, only using standard queues.

I was confounded, because long before an algorithm could form in my mind, I already decided that there was no solution that would actually be useful in any real life scenario.

That the only solution I could find; To be honest, I was too lazy to come up with the algorithm myself, but it’s really straight forward.

It has O(n) complexity, and… let’s just say it does not really scale.

But, it’s quite an interesting algorithm nonetheless. See, for a huge company to ask this question to every candidate, I can only assume one former employee found themselves stranded on an island, with a bunch of queues. Their survival depended on having a stack, they failed to come up with the proper solution and died.

It’s the only explanation that make sense to me; The other explanation would be that large companies ask really stupid & meaningless interview questions, and, well… that’s just silly.

Then, my friend told me the next question was about creating a queue using stacks.

Sure, why not ?

My friend and I debated about the complexity of this algorithm. I explained to him it was n². If our hero was stranded on an island, they could not have standard stacks shipped their way by amazon, and would have had to use what they had: a stack made of queues.

Of course, our unfortunate hero had a stock of standard queues to begin with, but maybe hey could’t use them, for some reason. After all, he didn’t invent them himself so it was better to rewrite them anyway.