TweakCode
Optimization lessons

Course 05 · Orientation

Optimization

Choose, then reuse

Sort intervals and make the greedy choice you can prove. Then stop recomputing overlapping subproblems: one dimension, then two.

Start with Intervals + Greedy

The course journey

Build one family of skills at a time

Each technique is three short lessons, and each one builds on the lesson before it. A lesson walks through one problem step by step, then hands it to you along with a few more to solve on your own.

  1. 01Start here

    Intervals + Greedy

    Sort intervals to merge overlaps, sweep their events to count peak load, and commit to the greedy choice that leaves the most room.

    1. Stage 1Sorting & Merging Overlapping IntervalsSort by start time so overlapping intervals sit adjacent and merge in one scan1 Lesson · 3 Problems
    2. Stage 2Sweep-Line & Concurrent Peak CountingTrack active intervals by sorting start/end events or maintaining a min-heap1 Lesson · 3 Problems
    3. Stage 3Greedy Choice by End Time or ReachCommit to the locally optimal choice that leaves the most room for what follows1 Lesson · 3 Problems
  2. 02Pro

    1D DP

    One index, a recurrence, a table. Then keep only the cells you still need.

    1. Stage 1

      Bottom-Up Tabulation

    2. Stage 2

      Include-or-Exclude DP

    3. Stage 3

      Unbounded Knapsack

    Preview
  3. 03Pro

    2D DP

    Two indexes: fill grids from their neighbors, align two sequences prefix by prefix, and track reachable sums against a budget.

    1. Stage 1

      Grid Path Tabulation

    2. Stage 2

      Two-Sequence Alignment (LCS / Edit Distance)

    3. Stage 3

      0/1 Knapsack & Target Sum Tables

    Preview