Algorithm Cheatsheets
Quick reference guides for algorithm patterns, implementation templates, and time complexity analysis.
Filter by tag:
📊
Array Patterns
🌳
Tree & Graph Patterns
🧠
Advanced Techniques
Sample: Two Pointers Cheatsheet
When to use:
- Finding pairs in a sorted array
- Removing duplicates from sorted arrays
- Squaring a sorted array
- Triplet problems (3Sum, 3Sum Closest)
Template:
function twoPointers(arr) { let left = 0; let right = arr.length - 1; while (left < right) { // Process the elements at left and right pointers // Move pointers based on condition if (condition) { left++; } else { right--; } } return result; }
Time & Space Complexity:
Time Complexity:
O(n) for most applications
Space Complexity:
O(1) for in-place operations