Patterns
- sliding window pattern
- subset pattern → no reptttion and repetttion
- Modified binary search
- top k elements → use heap
- binary tree dfs
- toplogical sort
- two pointer
- two moving pointer at diff speed
- two are in same direction
- Opposite direction
- prefix sum
- Linkindeni inplace reverse
- monotonic stock
- interval or range are overlap
- find interval and etc
- backtracking
- dynamic programming
- priorty queue
- Fast and Slow Pointer
- Cycle detection method
- O(1) space efficiency
- Linked list problems
- Merge Intervals
- Sort and merge
- O(n log n) complexity
- Overlapping interval handling
- Sliding Window
- Fixed/variable window
- O(n) time optimization
- Subarray/substring problems
- Islands (Matrix Traversal)
- DFS/BFS traversal
- Connected component detection
- 2D grid problems
- Two Pointers
- Dual pointer strategy
- Linear time complexity
- Array/list problems
- Cyclic Sort
- Sorting in cycles
- O(n) time complexity
- Constant space usage
- In-place Reversal of Linked List
- Reverse without extra space
- O(n) time efficiency
- Pointer manipulation technique
- Breadth First Search
- Level-by-level traversal
- Uses queue structure
- Shortest path problems
- Depth First Search
- Recursive/backtracking approach
- Uses stack (or recursion)
- Tree/graph traversal
- Two Heaps
- Max and min heaps
- Median tracking efficiently
- O(log n) insertions
- Subsets
- Generate all subsets
- Recursive or iterative
- Backtracking or bitmasking
- Modified Binary Search
- Search in variations
- O(log n) time
- Rotated/specialized arrays
- Bitwise XOR
- Toggle bits operation
- O(1) space complexity
- Efficient for pairing
- Top ‘K’ elements
- Use heap/quickselect
- O(n log k) time
- Efficient selection problem
- K-way Merge
- Merge sorted lists
- Min-heap based approach
- O(n log k) complexity
- 0/1 Knapsack (Dynamic Programming)
- Choose or skip items
- O(n * W) complexity
- Maximize value selection
- Unbounded Knapsack (Dynamic Programming)
- Unlimited item choices
- O(n * W) complexity
- Multiple item selection
- Topological Sort (Graphs)
- Directed acyclic graph
- Order dependency resolution
- Uses DFS or BFS
- Monotonic Stack
- Maintain increasing/decreasing stack
- Optimized for range queries
- O(n) time complexity
- Backtracking
- Recursive decision-making
- Explore all possibilities
- Pruning with constraints
- Union Find
- Track and merge connected components
- Used for disjoint sets
- Great for network connectivity
- Greedy Algorithm
- Make locally optimal choices
- Efficient for problems with optimal substructure
- Covers tasks like activity selection, minimum coins
1️⃣ Merge Intervals
2️⃣ Koko Eating Bananas
3️⃣ Search in Rotated Sorted Array
4️⃣ Detect a Cycle in Linked List
5️⃣ Word Search II
6️⃣ Gas Station
7️⃣ Sliding Window Maximum
8️⃣ Coin Change
9️⃣ Word Break
🔟 Edit Distance
1️⃣1️⃣ Trapping Rainwater
1️⃣2️⃣ Largest Rectangle in a Histogram
1️⃣3️⃣ Rod Cutting
1️⃣4️⃣ Binary Tree Maximum Path Sum
1️⃣5️⃣ Number of Distinct Islands
1️⃣6️⃣ Rotten Oranges
1️⃣7️⃣ Course Schedule II
1️⃣8️⃣ Pacific Atlantic Water Flow
1️⃣9️⃣ Cheapest Flights Within K Stops
2️⃣0️⃣ Min Cost to Connect All Points
These problems cover Greedy, DP, Graphs, Binary Search, Sliding Window, Trees, and more—helping to build a strong problem-solving mindset rather than just memorizing solutions.
💡 What I Learned Along the Way:
🔹 Quality over quantity—solving fewer problems deeply is better than rushing through many.
🔹 Pattern recognition matters—many problems share similar core ideas.
🔹 Revisiting and optimizing solutions—helps reinforce concepts and improve efficiency.
If you’re preparing for interviews, don’t focus on hitting a high problem count. Focus on understanding concepts, thinking deeply, and solving strategically.
Of course, sometimes we do need to practice more to get better. The key is to identify what works best for you—some may need more practice, while others improve by focusing on fewer problems but solving them deeply.
-
https://photonlines.substack.com/p/visual-focused-algorithms-cheat-sheet
-
https://www.kirupa.com/data_structures_algorithms/intro_data_structures_why.htm (best)
| Data Structure | Type | Operations (Time Complexity) | Use Cases |
|---|---|---|---|
| Array | Linear | Access: O(1), Insert/Delete: O(n) | Fixed-size collections, random access |
| Dynamic Array | Linear | Insert: Amortized O(1), Access: O(1) | Resizable array (e.g., Python lists) |
| Linked List | Linear | Insert/Delete: O(1), Access: O(n) | Dynamic memory allocation, stack/queue |
| Singly Linked List | Linear | Insert/Delete: O(1), Access: O(n) | Sequential data, simple structures |
| Doubly Linked List | Linear | Insert/Delete: O(1), Access: O(n) | More complex data traversal, memory management |
| Circular Linked List | Linear | Insert/Delete: O(1), Access: O(n) | Circular data, round-robin scheduling |
| Stack | Linear | Push/Pop: O(1) | Undo/redo functionality, parsing expressions |
| Queue | Linear | Enqueue/Dequeue: O(1) | Task scheduling, BFS |
| Deque | Linear | Insert/Remove from both ends: O(1) | Sliding window problems, stack/queue hybrid |
| Tree | Non-Linear | Insert/Search/Delete: O(log n) (avg) | Hierarchical data, binary search, sorting |
| Binary Tree | Non-Linear | Insert/Search/Delete: O(log n) (avg) | Tree traversal, hierarchical problems |
| Binary Search Tree (BST) | Non-Linear | Insert/Search/Delete: O(log n) (avg) | Fast searching, sorting, range queries |
| AVL Tree | Non-Linear | Insert/Search/Delete: O(log n) | Balanced search trees, optimized search |
| Heap | Non-Linear | Insert/Extract: O(log n) | Priority queues, sorting algorithms (heap sort) |
| Trie (Prefix Tree) | Non-Linear | Insert/Search: O(k), where k = string length | Autocomplete, dictionary, prefix matching |
| Graph | Non-Linear | BFS/DFS: O(V + E), Dijkstra: O(V log V) | Social networks, pathfinding, recommendation |
| Adjacency Matrix | Graph (Dense) | Insert/Search/Delete: O(1) | Dense graphs, quick edge lookups |
| Adjacency List | Graph (Sparse) | Insert/Search/Delete: O(V + E) | Sparse graphs, dynamic graph traversal |
| Directed Graph (Digraph) | Graph | BFS/DFS: O(V + E), Shortest path: O(V + E) | Directed dependencies, task scheduling |
| Undirected Graph | Graph | BFS/DFS: O(V + E), Shortest path: O(V + E) | Social networks, connectivity |
| Disjoint Set (Union-Find) | Specialized | Union/Find: O(α(n)) | Kruskal’s algorithm, network connectivity |
| Hash Table | Hashing | Insert/Search/Delete: O(1) | Caching, associative arrays, unique storage |
| Hash Set | Hashing | Insert/Search/Delete: O(1) | Set operations, removing duplicates |
| Priority Queue | Specialized | Insert: O(log n), Extract Min/Max: O(log n) | Task scheduling, Dijkstra’s algorithm, Huffman coding |
| Bloom Filter | Specialized (Probabilistic) | Insert/Check: O(1) | Membership testing, web caches, databases |
| Segment Tree | Advanced | Query/Update: O(log n) | Range queries, interval problems |
| Fenwick Tree (BIT) | Advanced | Query/Update: O(log n) | Prefix sum queries, cumulative frequency |
| Suffix Tree | String Processing | Search: O(m) where m is the pattern length | String matching, text processing |
| Suffix Array | String Processing | Search: O(log n) | Pattern matching, suffix-based searches |
| K-d Tree | Multi-dimensional | Insert/Search: O(log n) | Range searches, nearest neighbor searches |
| Quad Tree | Multi-dimensional | Insert/Search: O(log n) | Spatial partitioning, image processing |
| Octree | Multi-dimensional | Insert/Search: O(log n) | 3D data, computer graphics |
| Matrix | Multi-dimensional | Access: O(1), Operations: O(n^2) | 2D grid storage, dynamic programming |
| Skip List | Specialized | Insert/Search/Delete: O(log n) | Alternative to balanced trees, fast searching |
| Aho-Corasick | String Processing | Search: O(n + m + z) | Multi-pattern matching, dictionary matching |
| B-Tree | Tree (Balanced) | Search/Insert/Delete: O(log n) | Database indexing, file systems |
** LEVEL 1: FOUNDATIONAL PATTERNS** (Must-Know Before Anything Else)
Pointer-Based Techniques
- Two Pointers — converging/diverging on sorted arrays
- Fast & Slow Pointers — cycle detection, finding middle
- Sliding Window — contiguous subarrays/substrings
- Merge Intervals — overlapping ranges, scheduling
Search & Sort Variants
- Binary Search — and all modified versions
- Cyclic Sort — placing elements in their correct positions
- Insertion Sort Logic — relevant to some interval problems
Basic Graph Traversal
- BFS (Breadth-First Search) — level-order, shortest path (unweighted)
- DFS (Depth-First Search) — exploring all paths, connectivity
** LEVEL 2: STRUCTURAL PATTERNS** (Core Interview Techniques)
Array & Matrix Problems
- Island Pattern (Matrix Traversal) — connected components, flood fill
- Prefix Sum / Cumulative Sum — range queries
- Product of Array / Except Self — circular/prefix logic
Linked List Techniques
- In-place Reversal of Linked Lists — reversing segments
- Linked List Cycle — detection & finding start
Interval & Scheduling
- Insert & Merge Intervals — calendar problems
- Meeting Rooms — interval scheduling
Stack Variations
- Monotonic Stack — next greater/smaller element
- Valid Parentheses — bracket matching (basic but important)
** LEVEL 3: ADVANCED SEARCH & OPTIMIZATION** (Interview Gold)
Exhaustive Search
- Backtracking — N-Queens, permutations, combinations, Sudoku
- Subsets Generation — power set, all combinations
Binary Search Extensions
- Modified Binary Search — rotated arrays, find first/last occurrence
- Binary Search on Answer Space — minimizing/maximizing something
Bit Manipulation
- Bitwise XOR — finding unpaired elements, swap tricks
- Bit Masking — representing subsets, states
** LEVEL 4: DATA STRUCTURE OPTIMIZATION** (Efficiency Masters)
Heaps & Priority Queues
- Two Heaps Pattern — median finding, scheduling
- Top K Elements — k-th largest, frequency sorting
- K-way Merge — merging sorted streams/arrays
Hash Tables & Counting
- Anagrams & Grouping — character frequency patterns
- LRU Cache — double-linked list + hash map
Disjoint Sets
- Union-Find (Disjoint Set Union) — connectivity, cycle detection in undirected graphs
** LEVEL 5: DYNAMIC PROGRAMMING**
DP Fundamentals
- 0/1 Knapsack — bounded constraints, optimal selection
- Unbounded Knapsack — unlimited items
- Coin Change — minimum/maximum combinations
- Climbing Stairs — path counting patterns
DP on Sequences
- Longest Increasing Subsequence (LIS) — optimal subsequences
- Longest Common Subsequence (LCS) — sequence alignment
- Edit Distance (Levenshtein) — string transformation
- Maximum Subarray (Kadane’s Algorithm) — contiguous optimization
DP on Grids/2D
- Unique Paths — grid navigation with obstacles
- Minimum Path Sum — cost-based routing
- Matrix Chain Multiplication — parenthesization order
DP on Strings
- Word Break — segmentation, dictionary lookup
- Palindromic Substrings — longest/count
- Regular Expression Matching — pattern DP
DP with State Transition
- House Robber — state transitions with constraints
- Stock Trading (Multiple Transactions) — multi-state DP
- Paint House — color-based state DP
** LEVEL 6: GRAPH ALGORITHMS**
Shortest Path
- Dijkstra’s Algorithm — weighted shortest path
- Bellman-Ford Algorithm — negative weights, cycle detection
- Floyd-Warshall — all-pairs shortest path
Minimum Spanning Tree
- Kruskal’s Algorithm — MST via sorting + Union-Find
- Prim’s Algorithm — MST via priority queue
Connectivity & Flow
- Topological Sort — dependency ordering, DAG
- Strongly Connected Components (SCC) — Tarjan’s/Kosaraju’s
- Bipartite Check — 2-coloring via BFS/DFS
- Network Flow (Ford-Fulkerson) — max flow, min cut
** LEVEL 7: ADVANCED OPTIMIZATION**
Greedy Algorithms
- Activity Selection — interval scheduling
- Huffman Coding — optimal compression
- Fractional Knapsack — greedy vs DP comparison
- Jump Game / Reach — greedy forward leaps
Segment Trees & Range Queries
- Segment Trees — range sum/min/max queries with updates
- Fenwick Tree (Binary Indexed Tree) — efficient prefix sums
- Sparse Table — static range min/max
Tries & Pattern Matching
- Trie (Prefix Tree) — autocomplete, word search
- Suffix Arrays / Suffix Trees — pattern matching, text processing
Advanced String Algorithms
- KMP (Knuth-Morris-Pratt) — string pattern matching
- Rabin-Karp — rolling hash, pattern detection
- Z-Algorithm — linear time pattern matching
** LEVEL 8: COMPETITIVE/RARE PATTERNS** (If Time Permits)
Randomization & Probabilistic
- QuickSelect — finding k-th element without full sort
- Randomized Binary Search — probabilistic guarantees
Mathematical Patterns
- GCD / LCM Patterns — number theory
- Modular Arithmetic — large number handling
- Prime Sieve (Sieve of Eratosthenes) — generate primes efficiently
Combinatorial Patterns
- Next Permutation — lexicographic ordering
- Combination/Permutation Generation — systematic enumeration