SpaceX interview question

How do you reverse a stack, using only the pop and push methods?

Interview Answer

Anonymous

13 Oct 2017

In Java: public Stack reverse(Stack input){ Stack output = new Stack(); while(!input.isEmpty()) output.push(input.pop()); return output; }