Hashing-maps

45 articles

dsa9 min read

Find Common Characters — Frequency Intersection Across String Arrays

Find Common Characters teaches frequency intersection — the element-wise minimum of character counts across multiple strings. This pattern appears in multi-set intersection problems, resource allocation, and constraint satisfaction at tech company interviews.

Read →
dsa8 min read

Jewels and Stones — HashSet Membership Lookup Done Right

Jewels and Stones is the cleanest demonstration of the "build a lookup set, then query it" pattern. While the problem itself is easy, the skill it teaches — converting a repeated linear search into O(1) lookups — is fundamental to optimizing real-world code.

Read →
dsa8 min read

Group Anagrams — Canonical Keys and the Group-By Pattern

Group Anagrams is a medium-difficulty milestone that teaches the canonical-key grouping pattern — one of the most broadly applicable hash map techniques. Amazon, Google, and Meta use it as a filter for candidates who can design O(n k) grouping algorithms over O(n^2 k) brute-force comparisons.

Read →
dsa9 min read

Top K Frequent Elements — Bucket Sort Beats the Heap

Top K Frequent Elements is a classic interview problem that tests whether you know the O(n) bucket sort approach over the standard O(n log k) heap. Amazon, Google, Meta, and Microsoft all ask this problem because it reveals whether you can identify when domain constraints enable a better algorithm.

Read →
dsa9 min read

Subarray Sum Equals K — Prefix Sums and the Complement Map

Subarray Sum Equals K is the definitive prefix-sum hash map problem. It teaches the pattern of converting a range-sum query into a complement lookup — reducing O(n^2) to O(n). Amazon, Google, and Meta ask this in nearly every data-focused interview loop.

Read →
dsa10 min read

Continuous Subarray Sum — Prefix Modulo and Remainder Collisions

Continuous Subarray Sum applies the modular prefix sum trick — one of the most elegant applications of number theory to hash map design. Google uses this problem to test whether candidates can combine modular arithmetic with hash-map complement lookup.

Read →
dsa9 min read

Longest Consecutive Sequence — HashSet and the Smart Sequence Start

Longest Consecutive Sequence is a deceptively hard problem that Google and Meta use to test whether candidates can achieve O(n) without sorting. The key insight — only start counting from sequence beginnings — turns an O(n^2) brute force into an O(n) HashSet solution.

Read →
dsa9 min read

Insert Delete GetRandom O(1) — The Array+HashMap Design Trick

Insert Delete GetRandom O(1) is a classic design interview problem that Google, Amazon, and Meta use to assess compound data structure thinking. The trick — swapping the target with the last element before deletion — enables O(1) removal from a dynamic array.

Read →
dsa9 min read

Find All Anagrams in a String — Fixed Sliding Window With Frequency Matching

Find All Anagrams in a String combines the frequency-count pattern with a fixed sliding window — a compound technique that Google and Amazon use to filter candidates who understand both string hashing and window management. The "match counter" optimization is the key to an elegant O(n) solution.

Read →
dsa9 min read

Random Pick with Weight — Prefix Sums and Probabilistic Sampling

Random Pick with Weight teaches weighted random sampling — a foundational technique in machine learning, A/B testing, and traffic routing. Google and Meta use this problem to assess whether candidates understand prefix sums and binary search well enough to implement probability distributions from scratch.

Read →
dsa9 min read

Brick Wall — Counting Gap Positions With a Frequency Map

Brick Wall teaches the insight of counting the complement — instead of minimizing bricks crossed, maximize gaps hit. Google uses this problem to test whether candidates can reframe a minimization problem as a maximization problem and solve it in O(n) with a frequency map.

Read →
dsa8 min read

Unique Number of Occurrences — Double Hash Validation in One Pass

Unique Number of Occurrences teaches the double-hash technique: build a frequency map, then check if all frequency values are distinct. This two-layer hashing pattern appears in data validation, duplicate detection, and constraint checking problems at every major company.

Read →
dsa10 min read

Count Wonderful Substrings — Bitmask XOR and Prefix Parity Maps

Count Wonderful Substrings combines bitmask XOR with prefix parity tracking to count substrings where at most one character has an odd frequency. This advanced hashing problem teaches the bit-manipulation pattern that Google and Meta use to filter candidates for senior-level roles.

Read →
dsa6 min read

Make Sum Divisible by P — Prefix Mod With a Hashmap

LeetCode 1590 (Medium) shows up at Google, Amazon, and Microsoft. Find the shortest subarray whose sum mod P equals the total mod P, using a prefix-sum hashmap — a classic hash table FAANG pattern.

Read →
dsa8 min read

Design HashMap — Building a Hash Table from Scratch

Implement a HashMap from scratch using an array of buckets with chaining for collision resolution — the foundational data structure interview that every engineer should be able to implement cold.

Read →
dsa6 min read

Count Good Meals — Power-of-Two Complement Counting

LC 1711 Count Good Meals extends Two Sum to 22 power-of-two targets, counting pairs whose combined deliciousness is a power of 2 using a frequency map and complement lookup — tested at Amazon, Google, and Meta.

Read →
dsa7 min read

4Sum II — Meet in the Middle with a Frequency Map

LC 454 4Sum II counts 4-tuples from four arrays summing to zero by splitting into two pairs and using a frequency map — the meet-in-the-middle strategy that reduces O(n^4) to O(n^2), tested at Google, Amazon, and Microsoft.

Read →
dsa7 min read

Palindrome Pairs — HashMap Split Enumeration (Hard)

Find all index pairs (i, j) such that words[i] + words[j] forms a palindrome, using a reverse-word hashmap and systematic prefix/suffix palindrome splits in O(N * K^2) time. A FAANG hard problem that fuses string algorithms with hash table mastery.

Read →