← All topics

66 articles & lessons

Algorithms & Data Structures

Articles and learning notes on algorithms & data structures.

  1. LeetCode — From Basics to Production-Ready (65 Sessions)

    LeetCode is a motor skill, not a knowledge skill. A 65-session pattern-first curriculum: one pattern per session, five problems that are that pattern in disguise, and a spaced queue that makes it stick.

    18 min read
  2. Final Audit + Maintenance Plan

    Re-audit every pattern, compare against L59, and build the ongoing three-times-a-week loop that stops the whole thing decaying the moment the track ends.

    75 min read
  3. Contest Simulation

    A real timed LeetCode weekly contest — the closest available replica of timed-contest pressure, and the only place to practise performing rather than solving.

    75 min read
  4. Senior-Flavour Coding

    The hybrid round where coding meets design: rate limiters, LRU caches, schedulers and consistent hashing — built by composing primitives you already own.

    75 min read
  5. Company-Tagged — Microsoft & Amazon

    Work the frequency-ranked lists for the two companies that matter most to you, and adapt to each one's distinct review style rather than treating all loops as identical.

    75 min read
  6. Mock Set 3 — One Hard, 45 min

    Decomposing an unfamiliar Hard: find the seam where it splits into two Mediums, and practise being productive for 45 minutes without a full solution.

    75 min read
  7. Weak-Pattern Intensive

    Take the bottom three patterns from the L59 audit and repair them with the rebuild loop: blind template, three costumes, interleaved re-test.

    75 min read
  8. Blind 75 Sweep — Gap Audit

    Attempt-classify all 75 problems in one structured sweep, mark each cold, warm, hint or failed, and produce the personalised weak list that drives the rest of the track.

    75 min read
  9. Mock Set 2 — Narrated & Recorded

    Two unseen Mediums solved entirely out loud, screen and audio recorded, then played back — the fastest available fix for design review communication.

    75 min read
  10. Mock Set 1 — Mixed Easy/Medium, 45 min

    The first cold pressure test: two unseen Easy and two unseen Medium in 45 minutes, no hints, timer visible — run as an experiment that produces data about your classifier.

    75 min read
  11. Advanced Graphs

    Dijkstra as BFS with a priority queue, Bellman-Ford for negative weights and bounded hops, and the two minimum spanning tree algorithms — with the cue for choosing between them.

    75 min read
  12. String Algorithms

    KMP's failure function, rolling hashes, and the Z-function — the three ways to avoid re-comparing characters you have already matched.

    75 min read
  13. Segment Trees & Fenwick (BIT)

    Range query with point update in O(log n): the recursive segment tree skeleton, the Fenwick tree's low-bit trick, and how to recognise the rare problem that actually needs one.

    75 min read
  14. Sorting & Custom Comparators

    Partition-based selection and comparator design: Dutch national flag, quickselect for Kth largest in O(n) average, and cmp_to_key for orderings that are not a simple key.

    75 min read
  15. Design II — Streams & Time

    Two balanced heaps for a running median, binary search over versioned timestamps, and merging k sorted feeds — the design patterns for data that arrives over time.

    75 min read
  16. Design I — Composing for O(1)

    Hashmap plus doubly-linked list for LRU, array plus index map for GetRandom, and the general move of combining two structures so each covers the other's weakness.

    75 min read
  17. Matrix Manipulation

    Transpose then reverse to rotate in place, four-boundary control for spiral traversal, and using the first row and column as O(1) marker storage.

    75 min read
  18. Greedy — And Proving It Works

    Greedy feels right and is often wrong. The exchange argument, the counter-example hunt you should run first, and four problems where greedy genuinely is optimal.

    75 min read
  19. Intervals

    Sort by start, merge on overlap: the four-problem interval family, and why Meeting Rooms II needs a heap on top of the sort.

    75 min read
  20. Math & Number Theory

    Fast exponentiation by squaring, the sieve of Eratosthenes, Euclid's GCD, and binary search on integers — the four math routines worth memorising outright.

    75 min read
  21. Bit Manipulation

    XOR cancels itself, n & (n-1) clears the lowest set bit, and how to add two integers without the plus operator. The handful of bit tricks that actually recur in practice.

    75 min read
  22. Tries — Prefix Trees

    Children dict plus terminal flag: building a trie in ten lines, and why Word Search II is trie-plus-backtracking rather than a dictionary scan.

    75 min read
  23. DP XII — Bitmask DP

    Encoding a subset as an integer: when n is at most 20 the exponential state is affordable, the standard submask and popcount idioms, and why the constraint tells you before the problem does.

    75 min read
  24. DP XI — State Machine

    Naming your DP states explicitly: hold and free arrays for the stock problems, why drawing the transition diagram first collapses the difficulty, and how the k-transaction version generalises.

    75 min read
  25. DP X — Interval DP

    dp[i][j] over ranges with an inner split point k: why Burst Balloons only works when you think about the LAST balloon, and how sentinel padding removes the boundary cases.

    75 min read
  26. DP IX — Palindromes

    Expand-around-centre versus the 2D palindrome table: two O(n^2) approaches with very different failure rates, and when partitioning forces you back to explicit DP.

    75 min read
  27. DP VIII — String DP / Edit Distance

    The two-string DP table: dp[i][j] over prefixes, the three-way insert/delete/replace recurrence, and how Distinct Subsequences and Interleaving String are the same table with different transitions.

    75 min read
  28. DP VII — 2D Grid

    Grid DP is the friendliest dynamic programming: each cell is built from the one above and the one to its left. Use it to make DP feel mechanical before string DP.

    75 min read
  29. DP VI — Unbounded Knapsack

    The knapsack where each item is available in unlimited supply. One character changes from 0/1 — the capacity loop direction — and Coin Change, Rod Cutting, and Combination Sum IV all fall out of it.

    75 min read
  30. DP V — 0/1 Knapsack

    The single most reused DP shape in practice: a set of items, each taken at most once, under a capacity budget. Master the grid and the space-optimised 1D roll, and half of 'hard' DP becomes recognition.

    75 min read
  31. DP IV — Subsequences (LIS / LCS)

    Longest Increasing Subsequence and Longest Common Subsequence are the two parent problems behind a huge family. Know both cold and most subsequence DP becomes recognition.

    75 min read
  32. DP III — Take / Skip Decisions

    The binary-decision DP shape: at each index you either act or you don't. State machines for cooldown, reachability for Jump Game, and split points for Word Break.

    75 min read
  33. DP II — 1D Linear

    Define dp[i] in English before you write code. The House Robber family, and why most DP bugs are undefined state rather than a wrong transition.

    75 min read
  34. DP I — Recognising Overlapping Subproblems

    DP is recursion plus a cache. Write the recursion, add lru_cache, convert to a table — mechanically, in that order, every time.

    75 min read
  35. Backtracking II — Constraint Grids

    Pruning before you recurse, restoring board state exactly, and the O(1) validity checks that turn N-Queens and Sudoku from intractable into instant.

    75 min read
  36. Backtracking I — Subsets & Combinations

    One choose-explore-unchoose template that generates subsets, combinations and permutations, plus the two ways to skip duplicates without producing duplicate output.

    75 min read
  37. Graphs IV — Union-Find (DSU)

    Fifteen lines of disjoint-set union with path compression and union by rank, and the family of connectivity problems it collapses into near-constant time.

    75 min read
  38. Graphs III — Topological Sort

    Kahn's in-degree algorithm for ordering tasks with dependencies, and why a queue that empties early is exactly a cycle detector.

    75 min read
  39. Graphs II — BFS & Shortest Path

    Breadth-first search level by level, why it gives shortest paths in unweighted graphs, and the multi-source variant that solves nearest-X grid problems in one sweep.

    75 min read
  40. Graphs I — Representation & DFS

    Build the adjacency list, carry a visited set, and recognise that a grid is already a graph — then count connected components with a depth-first sweep.

    75 min read
  41. Heaps & Top-K

    When a problem asks for the K largest, K smallest, or K most frequent of anything, you almost never need to sort. A size-K heap answers it in O(n log k).

    75 min read
  42. Trees IV — Paths & Accumulators

    The return-one-thing-track-another pattern: a recursion whose return value serves the parent while a separate accumulator records the global best.

    75 min read
  43. Trees III — BST Properties

    Two views of a binary search tree: inorder traversal yields sorted order, and validation requires passing bounds down rather than comparing parent to child.

    75 min read
  44. Trees II — BFS / Level Order

    Snapshot the queue length at the top of each iteration and you have level-order traversal — the one trick behind right side view, zigzag, and minimum depth.

    60 min read
  45. Trees I — DFS Traversals

    Preorder, inorder and postorder as one recursive skeleton with the work line moved, plus the iterative forms and when they are worth writing.

    60 min read
  46. Recursion & the Call Stack

    Base case discipline, hand-tracing a call stack, and knowing when recursion is the wrong tool — the substrate under trees, backtracking and dynamic programming.

    60 min read
  47. Linked Lists II — Cycles, Middle, Reorder

    Floyd's tortoise and hare for cycle detection and entry point, finding the middle in one pass, and composing split-reverse-merge to reorder a list in O(1) space.

    75 min read
  48. Linked Lists I — Traversal & Reversal

    The dummy head that deletes most linked-list edge cases, and the prev/cur/next three-step reversal you should be able to write without thinking.

    75 min read
  49. Queues & Monotonic Deques

    The queue as BFS substrate, and the monotonic deque that answers sliding-window maximum in O(n) by discarding candidates that can never win again.

    75 min read
  50. Monotonic Stack

    Next greater and next smaller element in O(n): keep a stack whose order never breaks, and pop everything the current element resolves.

    75 min read
  51. Stacks — LIFO & Matching

    Nesting, matching, undo and expression evaluation are one idea: push what you expect, pop when it arrives, and carry auxiliary state alongside for O(1) queries like min.

    75 min read
  52. Binary Search III — On the Answer

    Stop searching the array and start searching the answer range: define a monotonic feasibility predicate, then binary search the smallest x for which it holds.

    60 min read
  53. Binary Search II — Rotated & 2D

    Binary search when the array is no longer sorted end-to-end: decide which half is still sorted, then discard the other. Same trick flattens a 2D matrix into one index space.

    60 min read
  54. Binary Search I — The Template

    One binary search template with a half-open invariant that never loops forever and never goes off by one, and the discipline of owning exactly one version of it.

    60 min read
  55. Prefix Sums & Difference Arrays

    Precomputing cumulative sums to answer range queries in O(1), and the prefix-plus-hashmap combination that counts subarrays where sliding windows are unsound.

    60 min read
  56. Sliding Window III — With Counts

    Windows whose validity depends on a frequency map, and the single integer counter that lets you test that condition in O(1) instead of rescanning the map.

    60 min read
  57. Sliding Window II — Variable Size

    Expand right unconditionally, shrink left while the invariant is broken, record at the right moment — and the amortisation argument that keeps it linear.

    60 min read
  58. Sliding Window I — Fixed Size

    Maintaining a window aggregate incrementally so that sliding costs O(1) instead of O(k), which turns the obvious O(n*k) scan into a single pass.

    60 min read
  59. Two Pointers II — Same Direction & Fast-Slow

    Two pointers moving the same way at different speeds: the read/write compaction you already know, and Floyd's cycle detection, which finds a loop in O(1) memory.

    60 min read
  60. Two Pointers I — Opposite Ends

    Two indices converging from the ends of a sorted array, and the monotonicity argument that proves you can discard a whole row of candidates with one comparison.

    75 min read
  61. UMPIRE — The Problem-Solving Framework

    A six-step process for the twenty minutes between reading a problem and having working code, so that being stuck becomes a step rather than a state.

    60 min read
  62. Hashing — Your Default Weapon

    The complement-lookup skeleton and the general move of trading memory for time, which is the first thing to try whenever a problem looks quadratic.

    60 min read
  63. Arrays & Strings — In-Place Discipline

    The read pointer and write pointer skeleton that solves a surprising share of Easy problems, and the index bookkeeping that makes it correct on the first try.

    60 min read
  64. Python for Speed — The 20 Idioms That Matter

    The small set of standard-library tools that turn a fifteen-line design review solution into a five-line one, and the syntax you must be able to type without thinking.

    60 min read
  65. Big-O in Practice — Counting, Not Vibes

    How to derive the cost of a Python data structure operation from how it is built, instead of memorising a table you half-remember under pressure.

    60 min read
  66. The LeetCode Game — How to Read a Problem

    Constraints are not decoration. They are a reviewer quietly telling you which complexity class is acceptable, and therefore which algorithm to reach for.

    60 min read