Skip to content

Greedy

Greedy means: at every step take the choice that looks best right now and never look back. It is only correct when you can argue the local best never hurts the future, so always ask "why can't this choice be a mistake?".

After this topic: You can propose a greedy rule, test it against a counter-example, and explain why it is safe.

Do these first: Heap / Priority Queue

0 of 8 solved0%

Step 1 · Read the lesson

Greedy

Take the best local choice and never undo it, when you can argue it is safe.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Maximum SubarrayMedium
  2. 2.Jump GameMedium
  3. 3.Jump Game IIMedium
  4. 4.Gas StationMedium
  5. 5.Hand of StraightsMedium
  6. 6.Merge Triplets to Form Target TripletMedium
  7. 7.Partition LabelsMedium
  8. 8.Valid Parenthesis StringMedium