Master individual coding patterns to solve algorithmic problems efficiently. This comprehensive cheatsheet covers 27 essential patterns with 300+ curated LeetCode problems.
0/360 Problems Solved
Fundamental array operations including traversal, manipulation, and optimization techniques.
String manipulation, parsing, and pattern matching techniques.
Precompute a prefix sum array where prefix[i] stores the sum of elements from index 0 to i. This enables quick sum queries over any subarray.
Use hash maps for O(1) lookups and efficient data organization.
Use two pointers (either moving towards or away from each other) to efficiently search or process elements in an array.
Maintain a dynamic window (subarray or substring) that slides over the input while updating required values efficiently.
Efficiently search sorted data by repeatedly dividing the search interval in half.
Apply binary search variations on sorted, rotated, or complex datasets.
Merge or process overlapping intervals in a sorted list.
Make locally optimal choices at each step with the hope of finding a global optimum.
LIFO data structure for parsing, expression evaluation, and monotonic operations.
Use a stack to maintain a sequence of increasing/decreasing elements to solve problems related to the 'next greater/smaller' elements.
Use two pointers moving at different speeds to detect cycles or find specific elements in linked lists.
Operations on singly and doubly linked lists including reversal, merging, and cycle detection.
Reverse sections of a linked list in place by adjusting pointers without extra memory.
Binary tree and BST operations including traversals, construction, and path problems.
Visit all nodes in a tree using different orders.
Navigate through matrices using BFS, DFS, or pattern-based traversal.
Explore as far as possible along each branch before backtracking.
Explore all nodes at the current depth before moving deeper.
Graph traversal, shortest paths, and connectivity problems.
Explore all possible choices recursively, undoing changes when necessary.
Priority queue operations for finding k-th elements and maintaining sorted streams.
Use heaps (priority queues) or quick-select to efficiently find the k largest/smallest elements.
Break a problem into smaller overlapping subproblems, store the results to avoid redundant computations (memoization or tabulation).
System design problems involving data structures and algorithms.
Mathematical concepts including number theory, bit manipulation, and arithmetic operations.