πŸ“¦

Arrays & Strings Cheat Sheet

Two pointers, sliding window, prefix sums β€” all patterns with time complexity.

πŸ”—

Linked List Operations

Insert, delete, reverse, detect cycle β€” with visual diagrams and code templates.

🌳

Tree Traversals Cheat Sheet

Inorder, preorder, postorder, BFS β€” recursive and iterative code in Python and C++.

⚑

DP Pattern Recognition Guide

How to identify DP problems + 8 core patterns with examples and state transitions.

πŸ€–

ML Algorithms Formula Sheet

Linear regression, gradient descent, loss functions, regularization β€” all key formulas.

🌐

Web Dev Quick Reference

CSS flexbox, grid, common JS patterns, fetch API β€” all on one printable sheet.

πŸ‘¨β€πŸ’» Code Templates

Reusable Code Snippets

Copy-paste these templates into your editor during practice.

πŸ” Binary Search Template (Python)

# Standard binary search
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = left + (right - left) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

πŸͺŸ Sliding Window Template (Python)

# Variable size sliding window
def sliding_window(arr):
    left = 0
    result = 0
    window = {}  # or a running sum
    
    for right in range(len(arr)):
        # Expand window
        window[arr[right]] = window.get(arr[right], 0) + 1
        
        # Shrink window (condition)
        while invalid(window):
            window[arr[left]] -= 1
            left += 1
        
        result = max(result, right - left + 1)
    return result

πŸ•ΈοΈ Graph BFS Template (Python)

from collections import deque

def bfs(graph, start):
    visited = {start}
    queue = deque([start])
    
    while queue:
        node = queue.popleft()
        process(node)  # do something
        
        for neighbor in graph[node]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append(neighbor)

⚑ 1D DP Template (Python)

# Bottom-up DP (Climbing Stairs)
def climb_stairs(n):
    if n <= 2:
        return n
    
    prev2, prev1 = 1, 2
    
    for i in range(3, n + 1):
        curr = prev1 + prev2
        prev2 = prev1
        prev1 = curr
    
    return prev1

# O(n) time, O(1) space βœ