Last Updated: July 15, 2025
Core Data Structures
| Structure | Operations | When to Use |
|---|---|---|
| Array/List | Access O(1), Insert O(n) | Indexed access, fixed size |
| Hash Map/Dict | All O(1) avg | Lookups, counting, caching |
| Stack | Push/Pop O(1) | DFS, backtracking, undo |
| Queue | Enq/Deq O(1) | BFS, scheduling, buffers |
| Binary Heap | Min/Max O(1), Insert O(log n) | Priority queues, top-K |
| Hash Set | Add/Remove O(1) | Deduplication, membership |
Algorithm Patterns
| Pattern | Signal | Example Problems |
|---|---|---|
| Two Pointers | Sorted array, subarray, palindromes | Two Sum II, 3Sum, Container with Most Water |
| Sliding Window | Contiguous subarray/substring | Longest substring without repeats |
| Binary Search | Sorted, search space pruning | Search rotated array, find peak |
| BFS/DFS | Tree, graph, shortest path unweighted | Number of islands, word ladder |
| Dynamic Programming | Optimal substructure, overlapping | Knapsack, LCS, coin change |
Time Complexity Quick Reference
| N | Max Acceptable Complexity |
|---|---|
| N ≤ 10 | O(N!) — brute force permutations |
| N ≤ 20 | O(2^N) — recursion, subsets |
| N ≤ 100 | O(N³) — Floyd-Warshall, triple loop |
| N ≤ 1,000 | O(N²) — nested loops, insertion sort |
| N ≤ 10⁵ | O(N log N) — sorting, heaps |
| N ≤ 10⁶ | O(N) — linear scan, hash map |
| N > 10⁷ | O(log N) or O(1) — binary search, math |
Interview Strategy
1. Clarify (2 min)Input format? Edge cases? Constraints? Duplicates?
2. Brute Force (2 min)State the naive approach, note its complexity
3. Optimize (5 min)Identify pattern, propose optimized approach
4. Code (10 min)Clean, named variables, handle edge cases
5. Test (3 min)Walk through with example, check edge cases
Pro Tip: Talk through your approach before writing code. Interviewers care more about your thought process than perfect syntax. Say the brute force first, then optimize.