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

Describe Java's HashMap implementation (post-Java 8): internal table of Node<K,V>, how load factor and threshold work (default loadFactor=0.75), when chains get converted into balanced trees, and how hashCode() and equals() are used. Explain pitfalls such as mutable keys and the effect of bad hashCode implementations.

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?

EasyTechnical
78 practiced

Describe the different causes of hash collisions in hash tables and provide practical production examples that can lead to high collision rates (e.g., poor hash function, small table size, adversarial input patterns, many similar prefixes). How would you detect collisions happening in a running system and what metrics would you collect?

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.

EasyTechnical
74 practiced

Explain the LRU (Least Recently Used) cache eviction policy. Describe how to implement LRU with O(1) get and put using common data structures, and why LRU is often a good default for many SRE caching use cases. Mention caveats under bursty access patterns.

Unlock Full Question Bank

Get access to all 41 Hashing and Hash Tables interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.