Hash Tables
Key-to-value lookup in average O(1) via hashing into buckets.
Hash Tables Practice Problems
Easy
4 problems- 380easy
Valid Anagram
Decide whether two words use exactly the same letters by counting the letters of one in a hash map and spending them on the other.
- 381easy
Contains Duplicate
Answer whether any value repeats in an array by keeping every value seen so far in a hash set and stopping at the first repeat.
- 382easy
Ransom Note
Check whether one string can be built from the letters of another by counting the available letters in a hash map and spending them.
- 383easy
First Unique Character in a String
Find the index of the first character that never repeats, using one pass to count every character and a second pass to find it.
Medium
4 problems- 384medium
Group Anagrams
Group words that are rearrangements of each other by filing every word in a hash map under the sorted letters that form its signature.
- 385medium
Valid Sudoku
Check a sudoku board for repeated digits in any row, column or 3 by 3 box by storing one combined key per rule in a hash set.
- 386medium
Design HashMap
Build a hash map from scratch with put, get and remove, using a fixed set of buckets and a list in each bucket to handle collisions.
- 387medium
Number of Boomerangs
Count ordered triples of points where two of them sit the same distance from the third, by tallying squared distances per anchor point.
Hard
2 problems- 388hard
Max Points on a Line
Find the most points sharing one straight line by tallying reduced direction keys in a hash map for every point taken as the anchor.
- 389hard
Insert Delete GetRandom O(1)
Support insert, remove and a fair random pick in constant time by pairing an array of values with a hash map from each value to its position.
Related concepts
| Topic | Description |
|---|---|
| Prefix Sum | Precompute running totals so the sum of any range can be answered instantly instead of adding it up every time. |
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Stacks | Last-in, first-out collection for undo, parsing, and nested work. |
| Queues | First-in, first-out collection for scheduling, BFS, and buffering. |
| Trees | Hierarchical nodes with parent–child links for ordered and nested data. |