Interview prep implementations with tests and complexity analysis.
| Category | Algorithm | Complexity | File |
|---|---|---|---|
| ๐ฆ Arrays | Two Sum (hash map + two-pointer) | O(n) | arrays/two_sum.py |
| ๐ฆ Arrays | Sliding Window (max sum, unique substr) | O(n) | arrays/sliding_window.py |
| ๐ฆ Arrays | Kadane's Algorithm (max subarray) | O(n) | arrays/kadane.py |
| ๐ฆ Arrays | Two Pointers (sorted sum, dedup, palindrome) | O(n) | arrays/two_pointers.py |
| ๐ค Strings | Anagram, Reverse Words, First Unique, LCP | O(n) | strings/manipulation.py |
| ๐ Linked Lists | Singly (push, pop, find, reverse) | O(1)/O(n) | linked_lists/singly.py |
| ๐ Stacks | Stack + Valid Parentheses | O(1) | stacks/stack.py |
| ๐ฌ Queues | Queue (deque-based) | O(1) | queues/queue.py |
| #๏ธโฃ Hash Maps | Custom HashMap (open addressing) | O(1) avg | hashmaps/hashmap.py |
| ๐ณ Trees | BST (insert, search, in-order) | O(log n) | trees/bst.py |
| โฐ๏ธ Heaps | Kth Largest, Top K Frequent, Merge K Sorted | O(n log k) | heaps/priority_queue.py |
| ๐ Graphs | BFS, DFS iterative + recursive | O(V+E) | graphs/traversals.py |
| ๐ Sorting | Quick Sort (in-place + functional) | O(n log n) | sorting/quick_sort.py |
| ๐ Sorting | Merge Sort (divide & conquer) | O(n log n) | sorting/merge_sort.py |
| ๐ Sorting | Heap Sort (in-place) | O(n log n) | sorting/heap_sort.py |
| ๐ Searching | Binary Search (iterative + recursive) | O(log n) | searching/binary_search.py |
| ๐งฎ Matrix | Rotate 90ยฐ, Spiral Order | O(nยฒ) | matrix/operations.py |
| ๐ Dynamic Programming | Fibonacci (memo + bottom-up), Climbing Stairs | O(n) | dynamic_programming/fibonacci.py |
| ๐ Backtracking | Permutations, Subsets (power set) | O(n!/2^n) | backtracking/permutations.py |
python -m pytest tests/ -v- Two pointers eliminates O(nยฒ) brute force on sorted arrays โ always ask "is it sorted?"
- Sliding window replaces nested loops for subarray/substring problems
- Kadane's is just a clever rolling max โ once you see it, you can't unsee it
- BFS = shortest path in unweighted graphs, DFS = explore everything
- Dynamic programming = recursion + memoization โ start top-down, optimize bottom-up
- Backtracking = DFS on a decision tree โ add, recurse, undo
- Heaps solve any "top K" problem efficiently โ
heapqin Python is a min-heap - Valid parentheses is the canonical stack problem โ learn the pattern, solve 10 variants
MIT