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

Design a memory-efficient approximate membership structure for very large sets of 64-bit integers where false positives are acceptable and false negatives are not (e.g., billions of elements). Compare Bloom filters, quotient filters, and compact hash tables in terms of memory per element, false positive rate, support for deletes, update cost, and concurrency. Suggest a practical in-memory design for a recent-items cache.

MediumTechnical
53 practiced

You're deduplicating JSON objects in a Python ETL job but records are Python dicts (unhashable). Describe approaches to make them usable as keys in a set/dict: canonical serialization (e.g., deterministic JSON), converting to sorted tuples, or computing stable fingerprints (e.g., SHA256). Discuss performance, correctness, and edge cases (ordering, floating point, missing fields).

HardTechnical
72 practiced

Implement a hash table from scratch (Java or C++) using open addressing with double hashing. Support insert, get, delete, and dynamic resizing. Describe handling of tombstones on delete, rehashing strategy during resize, and argue about amortized O(1) complexity. Include considerations for production concurrency.

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.

HardTechnical
76 practiced

You're evaluating hash functions to partition records across storage shards. Explain how you would design and test a robust hash function considering non-uniform key distributions, potential adversarial inputs, and collision properties. Compare modulo-based, cryptographic (SHA), and non-cryptographic (MurmurHash) approaches and explain when to salt or use keyed hashing.

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.