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.

MediumTechnical
71 practiced

Describe double hashing for open addressing and implement a Python function that generates the probe sequence indices for a given key and table size m. Explain how to choose the second hash function so the probe sequence visits every slot (i.e., h2 relatively prime to m).

HardTechnical
106 practiced

Provide a probabilistic analysis: under the uniform hashing assumption, derive the expected number of keys per bucket for separate chaining (n keys, m buckets), and use that to show expected lookup cost. Sketch the proof using balls-into-bins intuition and explain approximations used.

HardTechnical
75 practiced

A Python service that uses dicts as caches started OOM-ing after a deploy. Heap inspection shows many dict entries where keys are tuples containing large nested structures. As the SRE on-call, walk through your root-cause analysis steps, immediate mitigations to recover or mitigate without a full restart, and longer-term fixes to prevent recurrence.

HardSystem Design
55 practiced

Extend an LRU cache design to support per-entry TTL (time-to-live) and safe concurrent reads/writes from multiple threads. Describe the data structures, locking or sharding strategies to minimize contention, eviction rules when TTL expires, and how to handle race conditions between expiry and access.

EasyTechnical
53 practiced

You're mapping small integer keys in the range 0..K to values during preprocessing. Explain trade-offs between using a fixed-size array/list (direct indexing) versus a hash map/dictionary. Consider lookup speed, cache locality, memory overhead, sparsity (e.g., K=1e9 with only 1e6 keys present), and update patterns. Recommend approaches for dense and sparse scenarios.

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.