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.

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.

MediumTechnical
79 practiced

You're designing a composite key class in Java (e.g., composed of userId, eventType, and date) to be used as a HashMap key. Describe how you'd implement equals() and hashCode(), handling nulls and performance. Explain why immutability of fields matters and what can go wrong if fields are mutated after insertion into a HashMap.

HardTechnical
69 practiced

You maintain an in-memory ingestion service that uses hash maps intensively. Propose optimizations to improve cache locality and concurrency (for example sharded hash tables, open addressing, or prefetching). Explain trade-offs in code complexity, memory usage, and throughput, and how you'd benchmark changes.

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

Discuss the trade-offs between choosing a hash table capacity that is a power-of-two (allowing index = hash & (capacity - 1)) versus choosing a prime capacity and using modulo. Consider speed of indexing, distribution quality for bad hash functions, and ways modern implementations mitigate poor low-bit hash quality.

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.