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.

MediumTechnical
108 practiced

Describe robust strategies to hash composite keys (tuples of multiple fields) for hash tables. Explain common combination techniques (e.g., multiply-add mixing 31*prev + fieldHash, xor+rotations), handling nulls, order sensitivity, and producing stable hashes across language runtimes.

MediumTechnical
73 practiced

Discuss the trade-offs between choosing a hash table capacity that is a power-of-two (allowing index = hash & (capacity - 1)) versus choosing a prime capacity and using modulo. Consider speed of indexing, distribution quality for bad hash functions, and ways modern implementations mitigate poor low-bit hash quality.

HardSystem Design
99 practiced

Advanced system design: Design a multi-region consistent hashing layer for model cache routing where nodes have heterogeneous capacities (weights) and the system must minimize reshuffle when nodes are added or removed. Explain virtual node allocation proportional to weight, hashing strategies for mapping keys, replication policies across regions, and failure handling.

HardSystem Design
60 practiced

Design a streaming pipeline that maintains an approximate top-K frequent items view over a sliding 1-hour window at 100k events/sec. Propose an approach, justify the space/error trade-off you're making versus exact counting, explain how you'd implement the windowing, and how partial results would be aggregated across a distributed set of workers.

HardSystem Design
78 practiced

Design a distributed hash table (DHT) for a peer-to-peer system (e.g., Chord-like). Describe consistent hashing, node join and leave protocols, routing/lookup complexity, replication strategy for fault tolerance, and how you handle churn and rebalancing.

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.