hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Count Pairs with Sum
How many unordered pairs add to k? Keep frequencies of values already seen. For x, every previous k − x forms a valid pair. Then increment freq[x].
1, 5, 7, -1, 5, k = 6. Pairs are (1,5), (7,-1), (1,5) — answer 3.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Each element | O(1) expected |
| Full scan | O(n) |
| Space | O(n) |
Python implementation