SDE & MLE Prep

Greedy

When to use: a locally optimal choice can be proven to never hurt (exchange argument), usually after sorting or while tracking a running best/reach.

Typical shapes

  • Kadane: best subarray ending here = max(x, best_here + x).
  • Reach: track the farthest index reachable so far (jump games).
  • Sort then sweep: by end time, by height, by deadline.
  • Two passes (left→right, right→left) when each element has constraints from both sides (Candy).

If you can't argue why greedy is safe, fall back to DP.

Problems