// pattern debugger≡ menu

// algorithm pattern debugger

Coding-interview patterns the way a debugger teaches them: a universal template, then a step-by-step trace of real state — pointers, dictionaries, windows — at every iteration. All solutions in modern C#, every snippet compiled and behavior-checked.

patterns = 17
problems = 126
players = 13
language = C#

live: two_pointers on a sorted array — click the player, then keys step

L
1
0
3
1
5
2
7
3
R
11
4
step 1/4
Start. Array is SORTED — that's the license to use opposite-end pointers. Target = 10.
L = 0
R = 4
target = 10

template first

Each pattern is one skeleton; every problem is that skeleton with a different comparison in the middle. A required "template instance" note on every problem keeps the mapping honest.

traces are the product

Every problem carries a full iteration table — real pointer values, real dictionary contents — derived from actually executing the verified solution. No hand-waving, no "…".

verified C#

Every snippet is compiled and behavior-checked on .NET with edge cases (0, 1, 2 elements) before it reaches the page. The .NET-specific traps get called out where they bite.

Foundations

The ground everything else stands on — complexity, the C# toolkit, loop mechanics, sorting.

  • What O(n) actually buys you, the cost table for every .NET collection, amortized analysis, and how to state complexity in an interview.

  • Dictionary, HashSet, List, StringBuilder, PriorityQueue, Stack/Queue, LinkedList, spans, tuples, pattern matching, collection expressions — the modern C# you reach for under pressure.

  • for vs while, < vs <=, middle-element handling, ceiling division, negative modulo, direction arrays, mirror iteration, off-by-one defense, and the 0-1-2-element debugging technique.

  • What you must know about sorting without implementing it blind: comparison-sort floor, merge/quick mechanics, quickselect, counting & bucket sort, and when sorting is the setup move.

Core Patterns

The eight patterns behind the majority of interview problems. Learn these in order.

  • two_pointers7 problems · 2 ▶

    Two indices that converge, chase, or expand — turning O(n²) pair scans into O(n) walks on sorted or structured data.

  • hashmap6 problems · 1 ▶

    Trade O(n) space for O(1) lookups: value→index, value→count, prefixSum→count, and HashSet membership — the "key is what I need" mindset.

  • sliding_window4 problems · 1 ▶

    A window [L..R] that expands right and shrinks left over contiguous data — every element enters and leaves once, so O(n).

  • binary_search5 problems · 2 ▶

    Not "find a value" — find where a condition flips. Exact match, boundary finding, and binary search on the answer space.

  • bfs_dfs5 problems · 1 ▶

    The two traversal engines for graphs and grids: BFS for shortest/level-by-level, DFS for exhaustive exploration — plus multi-source BFS.

  • trees6 problems

    Preorder, inorder, postorder — recursive and iterative — and the tree problems interviews actually ask, each one a traversal wearing a costume.

  • linked_lists8 problems · 2 ▶

    Fast/slow pointers, the dummy head, reversal, merging — and the combo problems interviews love to build from them.

  • arrays8 problems · 2 ▶

    Prefix sums, in-place read/write, Dutch National Flag, Kadane, Boyer-Moore, matrix walks — the toolbox for array questions that fit no other pattern.

Data Structure Patterns

Stack, queue, heap, and trie — the structures that unlock their own problem families.

  • stack_queue6 problems · 1 ▶

    LIFO matching, design-a-stack problems, and the monotonic stack — the pattern behind every "next greater element" question.

  • heap5 problems

    PriorityQueue<TElement, TPriority> and the top-K family: keep a heap of size K, two heaps for medians — and when quickselect or buckets beat both.

  • trie3 problems

    A tree of characters where paths are prefixes — the structure for autocomplete, word dictionaries, and prefix search.

Advanced Patterns

Backtracking, DP, graph algorithms, greedy, intervals, bits — the rest of the 90%.

  • backtracking6 problems

    DFS over a decision tree: choose, explore, un-choose. Subsets, permutations, combinations — one template, different branching.

  • dp6 problems

    State + recurrence + base case. 1D, 2D, and string DP through the six problems that teach the whole method.

  • graphs4 problems · 1 ▶

    Beyond plain traversal: dependency ordering with Kahn's algorithm, connectivity with union-find, shortest paths with Dijkstra.

  • greedy4 problems

    Take the locally best move and prove you never regret it. Recognizing when greedy works — and when it silently doesn't.

  • intervals4 problems

    Sort by start (usually), then sweep: merge, insert, count overlaps. The pattern behind every calendar question.

  • bits4 problems

    XOR cancellation, n & (n−1), and the handful of bit identities that solve an entire question category in three lines.

How a Computer Runs Code

The primer, assuming nothing: bits and addresses, what the OS and a thread actually are, and how a CPU executes one instruction.

  • bits_memory1 problems

    Hex, two's complement, overflow as wraparound, alignment padding — and the one fact under everything: memory is a flat array of numbered bytes.

  • process_thread1 problems

    What the OS actually does for you, why user mode and kernel mode are separate, and the fact that explains the whole concurrency section: threads share the heap but never the stack.

  • cpu_execution2 problems

    Registers, the fetch-decode-execute loop, and what call and ret actually do to the stack — with the real disassembly to prove it.

Memory & the Machine

Stack, heap, virtual memory, caches, the pipeline, the collector, and the JIT — where your program's time and space actually go.

  • stack_heap2 problems

    Two allocators with different bills, and one piece of folklore to unlearn: a struct lives where it is declared, not "on the stack".

  • virtual_memory1 problems

    Every address your program sees is a lie the MMU maintains — pages, page faults, demand paging, and what "memory usage" really measures.

  • The cache line is the unit of everything. Locality is why two loops with identical Big-O differ by more than a factor of two.

  • cpu_pipeline2 problems

    Pipelining, branch prediction, and out-of-order execution — the machinery that makes your code fast, and that makes a memory model necessary.

  • gc_internals2 problems

    Allocation is a pointer bump; collection is the bill. Generations, the LOH, write barriers, and where p99 latency actually goes.

  • il_jit1 problems

    C# to IL to machine code: tiered compilation, inlining, bounds-check elimination, and the four reasons your micro-benchmark is lying to you.

Concurrency & Locking

The memory model, atomics, what a lock is made of, the hazards, lock-free structures, and parallelism that actually scales.

  • threads_async2 problems

    OS threads, pool threads, and Tasks are three different things. The state machine await compiles into, and the starvation you cause by blocking on it.

  • memory_model1 problems

    Atomicity, visibility, and ordering are three separate guarantees that "thread-safe" mushes into one word. volatile gives you some of them.

  • atomics_cas3 problems

    Why count++ is three operations, what the CPU does to fuse them into one, and the cache line two threads should never share.

  • locks2 problems

    An atomic word, a wait queue, and a way to park a thread. The uncontended path never enters the kernel — which is why contention costs what it does.

  • hazards2 problems

    Check-then-act and read-modify-write are the shapes almost every concurrency bug takes. Plus the four conditions every deadlock needs, and the async .Result trap.

  • lock_free2 problems

    What lock-free actually promises — progress, not speed. A Treiber stack from one CAS loop, and the two traps in ConcurrentDictionary.

  • parallelism2 problems

    Amdahl, coherence costs, and why adding threads can lower throughput. Partitioning is the answer; backpressure is not optional.

How the Network Works

The other half of the machine, assuming nothing: packets and layers, Ethernet and IP, what a port actually is, TCP versus UDP, DNS, the protocols on top, and what to run when none of it works.

  • From nothing: two machines, a link, and a message chopped into packets. Why the internet switches packets instead of holding a wire open, what bandwidth and latency each really cost, and why the whole thing had to be built in layers.

  • Seven layers on the exam, four in the code. The point of the model is encapsulation: watch one HTTP request grow a TCP header, an IP header and an Ethernet frame on the way out, and shed them again on the way in.

  • One hop at a time: MAC addresses, frames, what a switch learns and what a hub never did, how ARP turns an IP address into the MAC address of the next hop, and why MTU is the number that quietly breaks things.

  • Addresses that carry structure: IPv4 and IPv6, what a subnet mask actually masks, CIDR arithmetic done by hand, the routing table consulted for every packet, default gateways, NAT, and what TTL and traceroute are really doing.

  • ports_sockets1 problems

    A port is an integer in a header, not a thing. How the kernel uses the four-tuple to pick which socket gets a packet, why a listening socket and a connected socket are different objects, the ephemeral range, the accept queue, and where TIME_WAIT and port exhaustion come from.

  • tcp_udp1 problems

    The transport layer doing its two jobs: TCP turning a lossy packet network into an ordered byte stream — handshake, sequence numbers, acknowledgements, retransmission, windows — and UDP declining to, plus how to tell which one a problem actually wants.

  • The distributed lookup every request starts with: stub resolver, recursive resolver, root, TLD and authoritative servers; the records that matter; the TTL and the four caches between you and the answer; and the .NET traps that let a stale address outlive a failover.

  • What the stack was carrying: HTTP as text over a byte stream, request and response anatomy, statelessness and cookies, TLS in outline, WebSockets and gRPC for when request/response is the wrong shape, and the older protocols worth recognising.

  • The toolbox and the order to reach for it — name, reachability, route, port, TLS, payload — what each tool proves versus merely suggests, worked as a decision tree from "the service cannot reach the database".

System Design

The distributed layer: storage engines, transactions, replication, consistency, consensus, caching, queues and the drills that put them together.

  • Sizing a system before you build it: the numbers worth memorising, Little's Law, and why the mean latency is the least useful number on the dashboard.

  • What a database actually does with a write: pages and B-trees, log-structured merge trees, the write-ahead log, and the three amplifications you trade between.

  • ACID past the acronym: what each isolation level actually permits, the four anomalies, MVCC versus locking, and why serializable is rarer than people think.

  • Leader and follower, synchronous versus asynchronous, replication lag and the reads it breaks, quorums, and what a failover actually costs you.

  • Splitting data across machines: hash versus range, consistent hashing and why it exists, hot keys, rebalancing, and the secondary index problem nobody mentions.

  • Linearizable, sequential, causal, eventual — what each one promises, what it costs, and what CAP actually says as opposed to what it is usually quoted as saying.

  • Getting a cluster to agree: Raft leader election and log replication, why two-phase commit blocks, sagas and the outbox, and why a distributed lock needs a fencing token.

  • Cache-aside, write-through, write-behind; eviction policies and why LRU is not always right; TTL jitter, stampedes, negative caching, and the invalidation problem.

  • Delivery guarantees and why exactly-once is a claim to read carefully; offsets and consumer groups, ordering, dead letters, change data capture, and the outbox pattern.

  • What a request actually crosses: TCP handshakes and congestion control, HTTP/1.1 vs 2 vs 3, TLS, keep-alive and pooling, and L4 versus L7 load balancing.

  • Keeping a system up when its dependencies are not: timeout budgets, retries with jitter, circuit breakers, bulkheads, load shedding, and rate limiting that actually works.

  • drills4 problems

    The interview set, worked end to end: clarify, estimate, sketch, then defend the tradeoffs and name how it fails.

Deep Dives

Cross-pattern analyses: tradeoffs, recognition, and how the patterns fit together.

  • One problem, two tools: when sorting destroys information you need, when O(1) space wins, and the "key = what I need" framing.

  • The master decision table: read a problem statement, extract its signals, and name the pattern in under a minute.

Reference

  • study_plan

    Five tracks, run in order or dipped into: the core patterns, the rest of the pattern catalogue, how the machine runs code, how the network moves bytes, and the distributed layer.

  • cheat_sheet

    Every pattern's recognition signals, key tricks, and traps on one page. The night-before review.