BUG LAB · Stack
A minimum that outlives its value
A stack maintains one global minimum and never restores it on pop. Which sequence reveals the bug?
Java · intentionally broken snippet
void push(int x) {
stack.push(x);
min = Math.min(min, x);
}
void pop() { stack.pop(); }
int getMin() { return min; }Assume ordinary supporting code and valid inputs unless the question states otherwise.
Choose an answer before revealing the trace. Keys 1 to 3 work too.