← 返回 bytedance 的题目列表Implement HashMap put/get with Optimal Rehash Strategy
类型:online_judge
Implement a HashMap with put/get and an Optimal Rehash Strategy
Implement a simplified HashMap supporting:
put(key, value)
get(key) (return null/None if missing)
When the load factor exceeds a threshold, the map must resize. Additional requirement:
Discuss/implement a strategy to avoid rehashing all entries at once during resize (e.g., incremental rehash / gradual migration) to reduce worst-case latency.
Must cover
Collision handling (chaining/open addressing)
Resize trigger
Incremental rehash data structures and migration steps
Lookup logic during migration (old + new tables coexist)
Scale
Support ~1e5 keys with amortized performance.
Example tests
Basic put/get
Update existing key
After resize, all keys still retrievable
Mid-migration correctness
Performance doesn’t degrade to O(n)
Example
Input
put(1,10); get(1)
Output
10