InterviewStack.io LogoInterviewStack.io

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
70 practiced

Design and implement a Bloom filter for deduplicating seen document IDs during ingestion. Given expected n items and target false positive rate p, compute optimal bit array size m and number of hash functions k. Also implement insert and might_contain operations and discuss limitations such as no deletions and how Counting Bloom Filter addresses that.

HardTechnical
53 practiced

Theoretical/hard: For random-projection LSH applied to 128-d normalized vectors, derive how to choose the number of tables L and concatenated hash size k to achieve a target collision probability for vectors within radius r versus outside radius cr. Show the math relating collision probability to L and k and discuss practical trade-offs.

HardSystem Design
61 practiced

You must store and query billions of sparse (feature_id, value) pairs for real-time feature lookups. Propose a memory-efficient hash-based storage design: consider compact hash tables, open addressing with bit-packing, value quantization, sharding, memory-mapped files, and multi-level caching to keep latency low. Explain trade-offs and how you would evaluate the design.

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).

MediumTechnical
53 practiced

Describe building a token -> id vocabulary for NLP training: counting tokens from arrays of tokens, assigning ids, reserving special tokens (PAD, UNK, BOS, EOS), handling out-of-vocabulary tokens at inference, and memory/storage considerations when vocab size ~50M. Compare using hash maps vs sorted arrays and persistence formats for fast load.

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.