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

HardTechnical
61 practiced

Provide a formal argument proving that using dynamic array doubling (capacity *= 2) for hash table capacity yields amortized O(1) insertion cost. Analyze alternative growth factors (for instance 1.5x) and their impact on both time (amortized cost) and space (wasted capacity). Discuss when a smaller growth factor may be preferable for memory-limited services.

MediumTechnical
63 practiced

Implement an LRU cache in Python with the API: class LRUCache(capacity), get(key) -> value or -1, put(key, value). Requirements: O(1) get and put, memory bounded by capacity, evict least recently used item when full. Do not use collections.OrderedDict; implement underlying data structures. Also discuss thread-safety considerations in a multi-threaded SRE service.

MediumSystem Design
65 practiced

Design a caching layer for API responses in a microservice using a hash-based in-memory store. Explain what you would include in the cache key, how you would decide which entries to evict under memory pressure, how you would keep the cache from serving stale data, and how your approach changes once the service runs on multiple instances.

HardTechnical
59 practiced

Explain hash collision (hash-flooding) attacks and their effect on hash-table-backed services. As a data engineer, what would you deploy at the application and infrastructure level to make your pipeline's hash tables resilient to an attacker who can choose input keys?

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.