Arrays & Hashing
Store, look up and count data in O(1): the base of most coding interviews.
6 pages, free to read
- 1
Arrays & dynamic arrays
BeginnerAn array stores items side by side in memory so any index is reachable in O(1); a dynamic array adds automatic resizing so appends are O(1) on average.
9 min read - 2
Hash maps & hash sets
BeginnerA hash map turns a key into an array index with a hash function, giving O(1) average insert, delete and lookup; a hash set is the same structure storing keys only.
10 min read - 3
Prefix sums
IntermediatePrecompute running totals once in O(n) so the sum of any range is a single subtraction in O(1).
10 min read - 4
Counting & frequency maps
BeginnerCount how often each value appears in one O(n) pass, then answer anagram, duplicate, majority and top-k questions from the counts.
8 min read - 5
2D arrays & matrix traversal
IntermediateA matrix is a grid of rows and columns; most grid questions come down to visiting cells in the right order and stepping to neighbours with a direction list and a bounds check.
10 min read - 6
In-place array tricks
IntermediateSolve array problems with O(1) extra space by swapping, reversing, and using the array's own indexes and signs as storage.
10 min read