Pattern Hierarchy¶
Algorithmic API Kernels and their pattern instantiations with example problems.
SubstringSlidingWindow¶
Sliding Window Unique¶
- π‘ LeetCode 3 - Longest Substring Without Repeating Characters β
O(n) time, O(min(n, Ξ£)) space
Sliding Window At Most K Distinct¶
- π‘ LeetCode 340 - Longest Substring with At Most K Distinct Characters β
O(n) time, O(K) space
Sliding Window Freq Cover¶
- π΄ LeetCode 76 - Minimum Window Substring β
O(|s| + |t|) time, O(|t|) space - π‘ LeetCode 438 - Find All Anagrams in a String β
O(|s| + |p|) time, O(1) space for maps, O(k) for output - π‘ LeetCode 567 - Permutation in String β
O(|s1| + |s2|) time, O(1) space
Sliding Window Cost Bounded¶
- π‘ LeetCode 209 - Minimum Size Subarray Sum β
O(n) time, O(1) space
Sliding Window Fixed Size¶
- (No problems tagged yet)
GridBFSMultiSource¶
Grid Bfs Propagation¶
- π‘ LeetCode 994 - Rotting Oranges β
O(m*n) time, O(m*n) space
Bfs Shortest Path¶
- (No problems tagged yet)
KWayMerge¶
Merge K Sorted Heap¶
- π΄ LeetCode 23 - Merge k Sorted Lists β
O(N log k) time, O(k) space
Merge K Sorted Divide¶
- π΄ LeetCode 23 - Merge k Sorted Lists β
O(N log k) time, O(k) space
Merge Two Sorted¶
- π΄ LeetCode 4 - Median of Two Sorted Arrays β
O(m+n) time, O(1) space
MonotonicStack¶
Next Greater Element¶
- (No problems tagged yet)
Next Smaller Element¶
- (No problems tagged yet)
Histogram Max Rectangle¶
- (No problems tagged yet)
BinarySearchBoundary¶
Binary Search First True¶
- (No problems tagged yet)
Binary Search Last True¶
- (No problems tagged yet)
Binary Search On Answer¶
- π΄ LeetCode 4 - Median of Two Sorted Arrays β
O(m+n) time, O(1) space
Binary Search Rotated¶
- (No problems tagged yet)
UnionFindConnectivity¶
Union Find Connected Components¶
- (No problems tagged yet)
Union Find Cycle Detection¶
- (No problems tagged yet)
BacktrackingExploration¶
Backtracking Permutation¶
- (No problems tagged yet)
Backtracking Combination¶
- (No problems tagged yet)
Backtracking Subset¶
- (No problems tagged yet)
Backtracking N Queens¶
- π΄ LeetCode 51 - N-Queens β
O(n!) time
Backtracking Sudoku¶
- (No problems tagged yet)
LinkedListInPlaceReversal¶
Linked List K Group Reversal¶
- π΄ LeetCode 25 - Reverse Nodes in k-Group β
O(N) time, O(1) space
Linked List Full Reversal¶
- (No problems tagged yet)
Linked List Partial Reversal¶
- (No problems tagged yet)
TwoPointerPartition¶
Dutch Flag Partition¶
- π‘ LeetCode 75 - Sort Colors β
O(n) time, O(1) space
Two Way Partition¶
- π’ LeetCode 905 - Sort Array By Parity β
O(n) time, O(1) space - π’ LeetCode 922 - Sort Array By Parity II β
O(n) time, O(1) space
Quickselect Partition¶
- π‘ LeetCode 215 - Kth Largest Element in an Array β
O(n) average, O(nΒ²) worst case
TwoPointersTraversal¶
Two Pointer Opposite¶
- π’ LeetCode 1 - Two Sum β
O(n) time, O(n) space
Two Pointer Opposite Search¶
- (No problems tagged yet)
Two Pointer Opposite Palindrome¶
- π’ LeetCode 125 - Valid Palindrome β
O(n) time, O(1) space - π’ LeetCode 680 - Valid Palindrome II β
O(n) time, O(1) space
Two Pointer Opposite Maximize¶
- π‘ LeetCode 11 - Container With Most Water β
O(n) time, O(1) space
Two Pointer Same Direction¶
- (No problems tagged yet)
Two Pointer Writer Dedup¶
- π’ LeetCode 26 - Remove Duplicates from Sorted Array β
O(n) time, O(1) space - π‘ LeetCode 80 - Remove Duplicates from Sorted Array II β
O(n) time, O(1) space
Two Pointer Writer Remove¶
- π’ LeetCode 27 - Remove Element β
O(n) time, O(1) space
Two Pointer Writer Compact¶
- π’ LeetCode 283 - Move Zeroes β
O(n) time, O(1) space
Two Pointer Three Sum¶
- π‘ LeetCode 15 - 3Sum β
O(nΒ²) time, O(1) extra space - π‘ LeetCode 16 - 3Sum Closest β
O(nΒ²) time, O(1) extra space
Two Pointer K Sum¶
- (No problems tagged yet)
FastSlowPointers¶
Fast Slow Cycle Detect¶
- π’ LeetCode 141 - Linked List Cycle β
O(n) time, O(1) space
Fast Slow Cycle Start¶
- π‘ LeetCode 142 - Linked List Cycle II β
O(n) time, O(1) space
Fast Slow Midpoint¶
- π’ LeetCode 876 - Middle of the Linked List β
O(n) time, O(1) space
Fast Slow Implicit Cycle¶
- π’ LeetCode 202 - Happy Number β
O(log n) iterations, O(log n) per iteration
MergeSortedSequences¶
Merge Two Sorted Lists¶
- π’ LeetCode 21 - Merge Two Sorted Lists β
O(m + n) time, O(1) space
Merge Two Sorted Arrays¶
- π’ LeetCode 88 - Merge Sorted Array β
O(m + n) time, O(1) space
Merge Sorted From Ends¶
- π’ LeetCode 977 - Squares of a Sorted Array β
O(n) time, O(n) space
PrefixSumRangeQuery¶
Prefix Sum Range Query¶
- (No problems tagged yet)
Prefix Sum Subarray Sum¶
- (No problems tagged yet)
TreeTraversalDFS¶
Tree Dfs Recursive¶
- (No problems tagged yet)
Tree Dfs Iterative¶
- (No problems tagged yet)
TreeTraversalBFS¶
Bfs Level Order¶
- (No problems tagged yet)
DPSequence¶
Dp Fibonacci Style¶
- (No problems tagged yet)
Dp Longest Increasing¶
- (No problems tagged yet)
Dp Knapsack¶
- (No problems tagged yet)
DPInterval¶
Dp Palindrome¶
- (No problems tagged yet)
TopologicalSort¶
TriePrefixSearch¶
HeapTopK¶
Heap Top K¶
- (No problems tagged yet)
Heap Kth Element¶
- π‘ LeetCode 215 - Kth Largest Element in an Array β
O(n) average, O(nΒ²) worst case
Heap Median Stream¶
- (No problems tagged yet)