Skip to content
CodeItRaw
Path

Taking the best choice at every step and seeing why it is enough: change, jumps, meeting schedules and handing out.

Key ideas

  • Take what looks best right now, but be able to argue why that is enough.
  • With intervals, taking the one that ends first frees the room soonest.
  • If you can find a counterexample, the greedy choice is wrong: think DP instead.

Pattern

chosen = []
for item in sorted(items, key=most_promising_first):
    if fits(chosen, item):
        chosen.append(item)

Finish these first:Sorting

Lessons

Each lesson explains one idea from zero and ends with a few tasks. Lessons open in order; the explanation can be read at any time.

  1. 01

    The greedy choice, and where it holds

    0/3 tasks

  2. 02

    The farthest reach

    0/3 tasks

  3. 03

    Putting the decision off, and starting over

    0/2 tasks

  4. 04

    Greedy on intervals: earliest end first

    0/3 tasks

Boss

  • 05

    Candy

    Function

  • The boss opens when every lesson of the topic is finished. Solve it too and the topic is complete, and the topics after it open.