Bloomberg Interview Question

Write code to keep track of the running minimum in a stack.

Interview Answer

Anonymous

Aug 22, 2017

Use a second stack. If a new element pushed onto the stack is less than or equal to the current minimum (the top of the minimum stack), then push the new element onto the minimum stack. If an element is popped off the stack, if it's equal to the item on top of the minimum stack, pop off the top of the minimum stack.

5