← 返回 twosigma 的题目列表HashMap from Scratch
类型:qbank
Implement a hashmap without using built-in hash-table libraries. The round centers on buckets, collision handling, resizing, hash-function tradeoffs, and clean get/put semantics.
Requirements
Design and implement a hashmap from scratch. At minimum, support:
put(key, value)
get(key)
Do not use a built-in hash table / dictionary as the core storage.
Discussion topics include:
Bucket array layout.
Linked-list or equivalent chaining for collision resolution.
Hash-function choice and tradeoffs.
Load factor and resizing / rehashing.
Complexity under average and worst-case collision patterns.
Notes
The common baseline is an array of buckets, with each bucket storing a linked list of key-value pairs.
Resizing must rehash existing entries into the new bucket array; simply copying buckets by index is incorrect.
One candidate described the prompt as an upgraded version of a basic design-hashmap exercise, with more emphasis on discussion than just method implementation.
Preparation
Implement get, put, update-existing-key, and resize with separate chaining.
Be ready to discuss open addressing versus chaining, and why deletion is trickier with probing.
Test collisions deliberately by injecting a bad hash function.