Hashing and Hash Tables Questions

How hash tables and hash-based structures work internally, and how to reason about their performance and correctness. Covers hash function properties (determinism, uniform distribution, speed, avalanche effect), cryptographic versus non-cryptographic hash choices, collision resolution (separate chaining, open addressing: linear probing, quadratic probing, double hashing, Robin Hood hashing, cuckoo hashing), load factor and amortized-cost resizing, and what makes an object hashable (the __hash__/__eq__ contract, immutability, custom composite keys). Covers hash-map-backed cache design (LRU and LFU eviction, TTL) and thread-safe concurrent hash maps (lock striping, CAS-based updates, safe concurrent resizing). Also covers hash-based structures beyond arrays and strings: consistent hashing for distributed routing and sharding, hash joins, hash-flooding and algorithmic-complexity security attacks and their mitigations, and probabilistic membership/cardinality structures such as Bloom filters, Cuckoo filters, Count-Min Sketch, and HyperLogLog. Excludes using a hash map purely as an optimization trick inside an array or string problem (two-sum, group anagrams, longest substring without repeating characters); that pattern belongs to Arrays, Strings, and Hashing. This topic is about the hash table itself: how it is built, how it fails under skewed or adversarial input, and how it scales.

HardTechnical
75 practiced

You are on-call when a production service's 95th percentile latency jumps. Root cause: a hash table used for caching was fed adversarial inputs causing long collision chains and O(n) behavior, resulting in CPU saturation. Describe immediate remediation steps to restore availability, a post-incident analysis plan to determine root cause, and the concrete long-term changes you would propose.

HardSystem Design
65 practiced

Design a consistent hashing scheme to shard user data across N backend nodes with support for node addition/removal and replication factor R. Explain virtual nodes, ring traversal, replica placement, how to rebalance data with minimal movement, and approaches to handle hot keys.

HardTechnical
102 practiced

Hard problem: You must design an in-memory LRU cache for objects with variable sizes (in bytes) and a total memory budget M. Describe data structures and algorithms to support get(key) and put(key, value, size) such that on insertion you evict least-recently-used items until free memory >= size. Focus on complexity and correctness when sizes vary and discuss fragmentation issues.

HardSystem Design
64 practiced

You store tens of millions of items in an in-memory hash table. Resizing by rehashing everything causes long GC/stop-the-world pauses. Design an incremental or progressive resizing strategy that spreads rehash work across insert and lookup operations to avoid long pauses. Describe algorithms, required invariants, and how to preserve correctness during the transition period.

EasyTechnical
72 practiced

Explain the concept of load factor in hash tables and how it affects performance and memory usage. Describe the resize (rehash) operation when capacity is doubled and provide an amortized analysis showing that average insertion cost remains O(1). Discuss trade-offs of different resize thresholds (e.g., 0.5 vs 0.75).

Unlock Full Question Bank

Get access to all Hashing and Hash Tables interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.