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

Design a Bloom filter to deduplicate incoming event IDs in a high-throughput stream before expensive downstream processing. Explain how to choose the bit array size m and number of hash functions k for expected n items and target false positive rate p. Discuss persistence, reset strategy, and trade-offs compared to using a full hash set.

HardTechnical
75 practiced

You are on-call when a production service's 95th percentile latency jumps. Root cause: a hash table used for caching was fed adversarial inputs causing long collision chains and O(n) behavior, resulting in CPU saturation. Describe immediate remediation steps to restore availability, a post-incident analysis plan to determine root cause, and the concrete long-term changes you would propose.

HardTechnical
105 practiced

Implement MinHash for estimating Jaccard similarity between documents constructed from k-shingles (substrings of length k). Provide functions to compute shingles, generate multiple hash signatures, and estimate similarity. Discuss how many permutations (signature size) are needed to achieve a given variance in estimate and how MinHash is used in large-scale near-duplicate detection.

HardTechnical
64 practiced

Explain how equals() and hashCode() in Java interact and why inconsistent implementations can break hash-based caches and maps. Describe strategies to design key classes for caches which must remain stable across application versions and survive serialization, including avoiding volatile fields and using explicit versioning of key formats.

HardTechnical
65 practiced

Scenario: Your service counts requests per user at 100k QPS. The current Java implementation uses HashMap<Long, Integer> and is suffering from GC pauses and contention. Propose and justify a redesign to reduce GC, avoid boxing, and reduce contention. Include options like primitive collections, sharding, LongAdder, off-heap stores, and trade-offs.

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.