hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Find All Duplicates
The array has length n and every value is in 1..n. Some values appear once, some exactly twice. Count with a hash map and collect every key whose count becomes 2. Sorting the collected list makes the output stable.
4, 3, 2, 7, 8, 2, 3, 1. 2 and 3 each appear twice — they flash when their count hits 2.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Count pass | O(n) |
| Sort answer | O(d log d) |
| Space | O(n) |
Python implementation