hash_table.state
Input
Hash table
Current look-up
Match / window
Stored entry
What is Array Intersection
The intersection is the set of values that appear in both arrays. Put the first array into a hash set, then walk the second array and keep a value only when the set says yes.
1, 2, 2, 1, B = 2, 2. After A is in the set, both 2s from B hit, and the result set is just {2}.Interactive trace
Pseudocode & Complexity
| Operation | Time |
|---|---|
| Build set(A) | O(n) |
| Scan B | O(m) |
| Space | O(n) |
Python implementation