The duplicate handling is where I almost messed up.
Clarify that we need to count distinct value pairs (a, b) where a + b = target and a and b come from different indices, with the special case that a can equal b only if there are at least two occurrences of that value. Use a hash set to track seen values and another set to store unique pairs, iterating through the array and checking if target - current value exists in seen. Return the size of the pair set.
Pro tip: Mention that using a set for pairs automatically handles duplicates and the self-pairing condition, and discuss the trade-off between time and space complexity. Also, clarify edge cases like empty array or no pairs.
Confirm that pairs are unordered and distinct by value, and that a value can pair with itself only if it appears at least twice. Ask about input size and constraints.
Use a hash set to store seen values for O(1) lookups and another set to store unique pairs (as tuples or encoded values) to avoid duplicates.
For each number, compute complement = target - number. If complement is in seen, add the pair (min(number, complement), max(number, complement)) to the pair set. Then add number to seen.
When number equals complement, ensure that the value appears at least twice. This is naturally handled because the first occurrence adds to seen, and the second occurrence will find the complement in seen.
Return the size of the pair set. Discuss time complexity O(n) and space complexity O(n) due to the sets.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.