TodayILearned
Algorithms lessons
One fullstack engineering concept every day — taught deeply, then compressed into a public post.
Contains Duplicate — the hash set pattern
When 'have I seen this before?' is the question, a hash set is the answer.
Valid Anagram — the frequency count pattern
When the question is 'how many times?', a hash map is the answer.
Two Sum — hash map complement lookup
The #1 most-asked LeetCode problem. One pass, one hash map, one key insight: for each number, check if you've already seen its complement.
Group anagrams — sort key vs count key
Two ways to build a canonical key: sort each string (O(n × k log k)) or count characters (O(n × k)). The benchmark reveals a surprising crossover.
Top K Frequent Elements — Heap vs Bucket Sort
Day 5 counted frequencies. Day 12 grouped by frequency. Today: find the top K. Three approaches, three Big O complexities — and a benchmark that shows the textbook O(n) answer isn't always the fastest in practice.
Product of array except self — prefix × suffix
The no-division constraint forces a reframe: the answer for each position is the product of everything before it × everything after it. Two passes, O(n) time, O(1) space.