THN Interview Prep

Greedy

Greedy is not "pick what looks best" by instinct. It is correct only when you can defend the local choice with an invariant, exchange argument, or monotonic frontier.

Mental Model

  • Frontier: track the farthest reachable position or best boundary so far.
  • Exchange: show any optimal solution can be transformed to include your local choice.
  • Sorting key: choose the ordering that makes conflicts obvious.
  • Feasibility range: maintain lower/upper possible counts rather than one exact path.

Diagram

Loading diagram…

Problem List

Start with 055. Jump Game, 045. Jump Game II, 435. Non-overlapping Intervals, 763. Partition Labels, and 134. Gas Station.

Mark this page when you finish learning it.

Last updated on

Spotted something unclear or wrong on this page?

On this page