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.

HardSystem Design
65 practiced

Design a consistent hashing scheme to shard user data across N backend nodes with support for node addition/removal and replication factor R. Explain virtual nodes, ring traversal, replica placement, how to rebalance data with minimal movement, and approaches to handle hot keys.

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

Implement a HashSet in Java using open addressing with linear probing. Provide methods add(E key), contains(E key), and remove(E key). Ensure correct handling of tombstones, resizing, and rehashing. Discuss how you will avoid clustering and maintain performance as load factor grows.

EasyTechnical
74 practiced

Explain what hashing and hash tables are, and why hash tables provide average-case O(1) lookup, insertion, and deletion. Define keys, buckets, the role of the hash function, and show a concise example mapping string keys to bucket indices. Also state the assumptions behind the average-case claim and list conditions that would break it (e.g., adversarial inputs, very high load factor).

EasyTechnical
53 practiced

You're mapping small integer keys in the range 0..K to values during preprocessing. Explain trade-offs between using a fixed-size array/list (direct indexing) versus a hash map/dictionary. Consider lookup speed, cache locality, memory overhead, sparsity (e.g., K=1e9 with only 1e6 keys present), and update patterns. Recommend approaches for dense and sparse scenarios.

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.