BUG LAB · Stack
Half a bracket pair
The loop checks every closing bracket correctly, then returns true. Which input is incorrectly accepted?
Java · intentionally broken snippet
for (char c : s.toCharArray()) {
if (c == '(') stack.push(')');
else if (stack.isEmpty() || stack.pop() != c) return false;
}
return true;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.