SpaceX Interview Question

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

Interview Answer

Anonymous

Oct 13, 2017

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