BUG LAB · Arrays & hashing
One number, two indices?
The input promises one valid pair. Which case makes this implementation reuse an index?
Java · intentionally broken snippet
for (int i = 0; i < nums.length; i++) {
seen.put(nums[i], i);
int need = target - nums[i];
if (seen.containsKey(need))
return new int[]{seen.get(need), i};
}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.