Train the pattern first.
Then practice on LeetCode.

We are not another problem archive. We compress the gap between I read the problem and I see the trick from hours into minutes — with interactive animations that teach the mental model, not the syntax.

Two Pointers
Two indices moving over the same sequence to maintain an invariant — converging, fast/slow, sliding window.
converging · fast-slow · sliding
Binary Search Variants
Boundary conditions are the field's largest unsolved teaching problem.
3 variants · O(log n)
Backtracking
Decision-tree expansion — uniquely suited to animation.
branching state machine
Monotonic Stack
Stack-state transitions are invisible in code, dramatic in animation. The stack is the protagonist.
next-greater · histogram
BFS / DFS on Gr DFS
A queue gives breadth, a stack gives depth — same algorithm, two traversal orders.
queue · stack · flood fill
Heap & Priority Queue
Cheap access to the extreme — min or max — while everything else stays loosely ordered. A family of three sub-patterns: top-k, two heaps, k-way merge.
top-k · two-heaps · k-way-merge
Tree Traversal
Every traversal visits every node once — only when relative to children's recursion differs.
preorder · inorder · postorder · level
Linked List Manipulation
Three pointers — prev, curr, next — let you rewrite a list in place without losing the tail.
reverse · merge · reorder
Dynamic Programming
A table fills itself, one cell at a time — each entry composed from a constant number of earlier ones. A family of seven sub-patterns.
1-d · 2-d · knapsack · interval · state-machine · tree · bitmask
Union Find
Maintain a partition of N elements into disjoint components — merge two components in near-constant time, with the forest flattening itself on every query.
connected components · O(α(N))
Trie
Store a set of strings on a tree of characters — words that share a prefix share a path, and a single 'end-of-word' flag separates stored words from in-flight prefixes.
prefix queries · autocomplete · word-search
Topological Sort
Linearize a directed acyclic graph so every edge points left-to-right — each node enters the order only after every prerequisite has already left.
Kahn's algorithm · O(V + E) · cycle detection
Prefix Sum
Pay O(N) once to amortize every range query to O(1) — and flip it inside-out for cheap range updates. A family of four sub-patterns.
1-d · 2-d · difference · hash-map
Shortest Path
Find the shortest route from a source — the mechanism splits by what the edges carry. BFS for uniform costs, Dijkstra for non-negative, Bellman-Ford for negatives, Floyd-Warshall for all pairs.
BFS · Dijkstra · Bellman-Ford · Floyd-Warshall
Merge Intervals
Sort by start, then sweep — each interval either extends the current merge or commits it and starts a new one. The whole pattern lives in that one comparison.
sort + linear sweep · O(N log N)
Bit Manipulation
Treat integers as their bits, not their values — XOR a number against itself to zero it, against zero to keep it. The trick is recognizing when a problem has a hidden bit-level structure.
XOR · bit mask · O(N)
Cyclic Sort
When values live in [0, N] or [1, N], the index IS the pointer — swap to home or sign-flip to mark seen. Missing/duplicate problems collapse to O(N) time, O(1) space.
index-as-pointer · O(N)
Sweep Line
Turn each interval into a +1 event at its start and a −1 event at its end, sort by position, then sweep. The running active count rises and falls — its peak is the answer for max-concurrent problems.
endpoint events · running max · O(N log N)
Greedy
At every step, take the locally optimal commit — and prove it never gets undone. No backtracking, no DP table.
interval-scheduling · jump-game · gas-station
Segment Tree
A balanced binary tree whose nodes hold range aggregates. Any range decomposes into O(log N) canonical pieces — so queries and point updates are both O(log N).
range query · point update · O(log N)
Fenwick Tree
An implicit tree via the lowest set bit — O(log N) point updates and prefix sums in ten lines of code, no nodes to allocate.
implicit tree · lowbit · O(log N)
String Matching
Find P inside T in O(N + M) instead of O(N·M). Three sub-patterns differ only in what they precompute from the pattern: failure function, rolling hash, or Z-array.
kmp · rabin-karp · z-algorithm
Matrix
A 2-D coordinate space with two indices. The trick is the walk order — transpose+reverse, perimeter shrink, or monotone-corner staircase.
rotate · spiral · staircase-search
Math & Number Theory
Recognize the number-theoretic structure (divisibility, modular, multiplicative) and an O(N) loop collapses to O(log N) or O(N log log N).
gcd-lcm · modular-power · prime-sieve
Minimum Spanning Tree
Cheapest way to connect every node of a weighted graph — exactly N−1 edges, no cycles, minimum total weight.
kruskal · prim
Cache Eviction
Fixed-capacity store with O(1) get and put. Every eviction policy is a different answer to "which entry do I drop when full?"
lru · lfu · O(1) get/put
Monotonic Deque
Two ends, two jobs — front evicts when the window slides past, back drops what's dominated. The front is always the window's max in O(1).
sliding-window max · O(N)
Bidirectional BFS
Run BFS from both endpoints; meet in the middle. Cuts shortest-path search from O(b^d) to O(b^(d/2)) when both source and target are known.
meet-in-the-middle · O(b^(d/2))
Linear Algebra Primerarticle
The minimum linear algebra you need before any Transformer diagram — vectors, dot products, matrix multiplication, cosine similarity, norm, transpose. Visual and short.
Probability & Statistics Primerarticle
The minimum probability you need before any LLM training paper — what a probability is, distributions, conditional probability, expectation and variance, log probabilities. Prose-first and short.
Calculus Primerarticle
The minimum calculus you need before any deep-learning paper — derivative, partial derivative, the chain rule (= backprop), and the gradient that drives every optimizer. No integrals.
Data Fundamentals Primerarticle
The minimum data plumbing every ML pipeline needs — samples, features and labels, the train/val/test split, ASCII / UTF-8 (the bytes LLMs actually consume), and standardize-and-clean preprocessing.
Supervised Learning Primerarticle
The minimum learning theory you need before any ML paper — the input-to-output mapping, the loss function, gradient-based optimization, overfitting vs generalization, and the regularizers that keep models honest.
Gradient Descent Primerarticle
The optimizer that trains every modern model — the one-line update rule, the most-tuned hyperparameter (learning rate), SGD with mini-batches, the epoch / iteration / step vocabulary, and the loop that runs millions of times.
Neural Net Primerarticle
The building blocks of every deep model — a single neuron, the activation functions that make non-linearity possible, layers (the rows of neurons that share an input), and the forward pass that walks input through them all.
Backprop Primerarticle
The algorithm that turns 'compute the gradient' from impossible to one-pass cheap — backpropagation via the chain rule, why weights can't all start at zero, the vanishing / exploding gradient problem, and the MLP that sits inside every Transformer block.
Loss & Stability Primerarticle
Four tools every deep-learning paper assumes you know — softmax (scores → distribution), cross-entropy (the loss that pairs with it), dropout (the brutalest regularizer), and BatchNorm / LayerNorm (the layer that keeps activations sane).
Text in LLMs Primerarticle
Why text is the hardest data type in ML and the exact problem the Transformer solves — variable length, order that flips meaning, every token's meaning depending on context, and the landscape of pre-Transformer approaches that each handle some of these but never all three.
RNN & LSTM Primerarticle
The optional pre-Transformer history — the basic RNN that processes one token at a time, the LSTM / GRU gated variants that fixed the vanishing-gradient problem, and the three structural wins (parallelism, long-range memory, no bottleneck) that ended the recurrent era.
Hardware & Tensors Primerarticle
The physical layer of deep learning — why GPUs eat the workload (thousands of dumb-but-parallel cores), why VRAM is the hardest constraint on what LLM you can run, what a tensor is, and how batch / padding / mask turn variable-length text into GPU-friendly rectangles.
Frameworks & Autograd Primerarticle
The software layer of deep learning — PyTorch, JAX, and TensorFlow at a glance, autograd (you write the forward pass and the framework hands you every gradient for free), and the computational graph that makes the trick possible.
Optimizers & Training Tricks Primerarticle
The training-machinery primer for LLMs — SGD → Adam → AdamW (the LLM default), learning-rate schedules (warmup + cosine decay), mixed-precision training (fp16 / bf16), and the three distributed-training axes (data / tensor / pipeline parallel) that make trillion-parameter training possible.
Word Embeddings Primerarticle
Text → numbers: the journey from sparse one-hot vectors to dense word embeddings (Word2Vec, GloVe), the famous king − man + woman ≈ queen analogy, and why static embeddings still aren't enough — they have no context.
Tokenization Primerarticle
How text becomes the input to an LLM — the character / word / subword trade-off, BPE (the algorithm GPT uses), WordPiece / SentencePiece / Unigram, and why modern LLM vocabularies sit between 50,000 and 200,000 tokens.
Self-Attention Primerarticle
The mechanism at the heart of every Transformer — Query / Key / Value, the score matrix Q · Kᵀ, the scaled dot-product with √d_k and softmax, and the weighted sum of values. A complete tiny example, end to end.
Multi-Head Attention Primerarticle
Why one attention head isn't enough — split, run in parallel, combine. The dimensions of Q/K/V split across h heads, each learns a different kind of relationship, and a final W_O projection mixes their outputs back together.
Positional Encoding Primerarticle
Self-attention is order-blind. To fix that, Transformers inject position information into each token — through sinusoidal patterns (original paper), learned embeddings (GPT-2), or RoPE (the modern standard, used by Llama, Qwen, DeepSeek).
Transformer Block Primerarticle
The full structure of one Transformer block — LayerNorm / RMSNorm, residual connections, position-wise FFN — and how N of these blocks stack into a complete model. The capstone of the AI prerequisite stack.
Transformer Forward Passcoming soon
Walk one prompt all the way through a modern LLM — tokenize, encode position, attend, decode the next token, cache for reuse. Five ordered stages, each its own pattern.
tokenize · encode · attend · decode · cache
Binary & Number Systems Primerarticle
Every byte your program touches is just 8 bits — two's complement for integers, IEEE-754 for floats, big-endian vs little-endian for memory layout. The substrate every layer above assumes.
CPU Architecture Primerarticle
Inside one core — registers, ALU, control unit, a pipelined fetch / decode / execute loop, branch predictor, and out-of-order execution. Why your tight loop runs 20× faster than the assembly suggests.
Memory Hierarchy Primerarticle
Six orders of magnitude separate L1 cache (1 ns) from disk (10 ms). Locality of reference is the single rule that decides whether your code feels fast or slow.
Cache Coherence Primerarticle
MESI keeps multi-core caches consistent — and false sharing on a single 64-byte cache line can quietly cut multithreaded throughput in half.
Assembly & ISA Primerarticle
What the compiler actually emits — x86 vs ARM, registers vs memory, why a syscall is special. The thin glue between your code and the silicon.
Process & Thread Primerarticle
A process is an address space plus a PCB; a thread is a runnable context inside it. User mode vs kernel mode, and the 1–2 μs context switch every syscall pays for.
CPU Scheduling Primerarticle
How Linux CFS decides who runs next — virtual runtime, nice values, preemption, real-time policies. The 'why is my latency-sensitive task starving?' answer lives here.
Virtual Memory Primerarticle
Page tables, the TLB, page faults, mmap, copy-on-write, swap. Every pointer you dereference is one translation away from physical RAM.
Memory Allocation Primerarticle
Stack vs heap, malloc / free, fragmentation, jemalloc / tcmalloc / mimalloc. Why swapping the allocator can double the throughput of a multithreaded server.
Syscalls & Interrupts Primerarticle
The two ways control crosses the user / kernel line — your code asking (syscall) or hardware demanding (interrupt). The plumbing every I/O depends on.
File System Primerarticle
Inodes, directories, journaling, the page cache, and the brutal honesty of fsync. Why 'I wrote it' and 'it survives a crash' are two different statements.
I/O Models Primerarticle
Blocking vs non-blocking vs select / poll / epoll / kqueue / io_uring, plus zero-copy. The architectural choice that separates 1K from 1M concurrent connections.
Concurrency Primitives Primerarticle
Mutex, semaphore, condvar, futex, atomics, memory ordering. The tools every lock-free or lock-based algorithm is built from — and the one (memory ordering) everyone gets wrong.
Network Stack Primerarticle
OSI in practice — how a packet leaves your socket and reaches the network card. Ethernet frame, IP header, TCP / UDP segment, wrapped in 14 + 20 + 20 bytes.
TCP Deep Dive Primerarticle
Three-way handshake, sliding window, congestion control (Reno → CUBIC → BBR), TIME_WAIT, Nagle. The 'why is my connection slow?' answer lives somewhere in here.
DNS & HTTP Primerarticle
How a hostname becomes an IP; HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC); keep-alive, headers, body framing. The application layer every web stack sits on.
TLS & Security Primerarticle
TLS 1.3 handshake, X.509 certificates, the PKI trust chain, mTLS. How the green padlock actually works — and what breaks when it doesn't.
Disk Storage Primerarticle
HDD seek time vs SSD random reads, IOPS vs throughput, write amplification, RAID levels. The physics under every database.
Database Storage Primerarticle
B-tree (Postgres / MySQL) vs LSM-tree (RocksDB / Cassandra), WAL, page management, buffer pool. The data structures that decide write throughput vs read latency.
Transactions Primerarticle
ACID, the four isolation levels and what they actually prevent, MVCC, two-phase commit. Why 'consistent' means different things to different databases.
Anatomy of a Web Request Primerarticle
Trace one `curl https://api.example.com/user/42` end to end — keystroke, syscall, TCP, TLS, DNS, kernel scheduler, page cache, B-tree lookup, all the way back. The capstone that names every primer in this stack.