Implement a Hash Map With Separate Chaining and Automatic Resizing
Last updated: November 29, 2026
Quick Overview
Implement a hash map supporting put(key, value), get(key) and remove(key) for integer keys, using separate chaining and doubling the bucket array when the load factor exceeds 0.75, without using Python's dict.
0
0
0 solved
Implement a hash map supporting put(key, value), get(key) and remove(key) for integer keys, using separate chaining and doubling the bucket array when the load factor exceeds 0.75, without using Python's dict.
Google onsites sometimes ask you to build the data structure you would normally take for granted. The interviewer checks bucket indexing, update-versus-insert semantics, rehashing on resize, and your ability to discuss load factor, collision behavior and amortized O(1) operations.
What the Interviewer Expects
- Chooses an initial capacity and a hashing function
- Handles update of an existing key separately from insert
- Resizes and rehashes all entries when load factor is exceeded
- Explains amortized O(1) via geometric growth
- Discusses chaining versus open addressing trade-offs
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Switch to open addressing with linear probing; how do deletions work (tombstones)?
- How would you make this thread-safe without a single global lock?
- What happens with a poor hash function and adversarial keys, and how do real maps defend against it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
put(key, value): insert or overwrite.get(key): return the value or -1 if absent.remove(key): delete if present.- Keys are integers; average O(1) per operation; grow capacity when `size ...
High-Level Design
Store an array of buckets, each a Python list of [key, value] pairs. The bucket index is hash(key) % capacity; for integers I mix bits a little so sequential keys do not cluster in power-of-two ta...