Common Data Structures and Algorithms Patterns
Pattern 1: Fast and Slow Pointers
| Problem Link | Articles | Solution |
| Linked List Cycle | Github | |
| Happy Number | Github | |
| Find the duplicate number |
Pattern 2: Sliding Window
| Problem Link | Articles | Solution |
| Maximum Average Subarray | Github | |
| Longest Substring Without Repeating Character | Github | |
| Minimum window substring | Github |
Pattern 3: Merge Intervals/Overlapping Intervals
| Problem Link | Articles | Solution |
| Merge Intervals | Github | |
| Insert Intervals | Linear Search, Binary Search | |
| Non-overlapping Intervals |
Pattern 4: LinkedList In-place Reversal
| Problem Link | Articles | Solution |
| Reverse Linked List | Iterative, Recursive | |
| Reverse Linked List II | ||
| Swap Nodes in Pairs |
Pattern 5: Prefix Sum
| Problem Link | Articles | Solution |
| Range Sum Query - Immutable | Github | |
| Contiguous Array | Github | |
| Subarray Sum Equals K | Github |
Pattern 6: Top ‘K’ Elements
| Problem Link | Articles | Solution |
| Kth Largest Element in an Array | Github | |
| Top K Frequent Elements | Github | |
| Find K Pairs with Smallest Sums | Github |
Pattern 7: Binary Search
| Problem Link | Articles | Solution |
| Search in a rotated sorted array | Github | |
| Find Minimum in a rotated sorted array | Github | |
| Search a 2D matrix II | Github |
Pattern 8: Binary Tree Traversal
| Problem Link | Articles | Solution |
| Binary Tree Paths | Github | |
| K-th Smallest Element in BST | Recursive, Iterative | |
| Binary Tree Maximum Path Sum | ||
| Inorder Traversal | Github | |
| Symmetric Tree | Github |
Pattern 9: Depth First Search
| Problem Link | Articles | Solution |
| Clone Graph | Github | |
| Path Sum II | Github | |
| Course Schedule II | ||
| Same Tree | Github | |
| Number of Provinces | Github (DFS) |
Pattern 10: Breadth First Search
| Problem Link | Articles | Solution |
| Level Order Traversal | GitHub | |
| Rotting Oranges | Github | |
| Word Ladder | ||
| Clone Graph | Github | |
| If Path Exists | BFS, Union Find |
Pattern 11: Matrix Traversal
| Problem Link | Articles | Solution |
| Flood Fill | Github | |
| Number of Islands | Github | |
| Surrounded Regions | Github | |
| Number of Closed Islands | Without global variable, with global variable (cleaner, but not best practice) |
Pattern 12: Backtracking
Pattern 13: Monotonic Stack
| Problem Link | Articles | Solution |
| Next Greater Element I | Github | |
| Daily Temperatures | ||
| Largest Rectangle in Histogram |
Pattern 14: Generic Graphs
| Problem Link | Articles | Solution |
| Minimum Number of Vertices to Reach All Nodes | Solution | |