LeetEye LeetEye
Pattern

Greedy

Make locally optimal choices for globally optimal solutions.

8 Problems
0 Easy
8 Medium
0 Hard

How Greedy Works

Greedy pattern visualization

Greedy algorithms make the locally optimal choice at each step, trusting that it leads to a globally optimal solution. The key is proving the greedy choice property: that selecting the best option at each step never prevents finding the overall best solution. Common techniques include sorting by deadline/end time for scheduling, always picking the largest/smallest available element, and interval scheduling (sort by end time, pick non-overlapping). Greedy works when local decisions don't need to be revised.

When to Use Greedy

Pattern Recognition

Look for these trigger words in problem statements:

maximum subarray greedy jump game jump game ii gas station hand of straights merge triplets to form target triplet partition labels valid parenthesis string

Common Mistakes

  • Assuming greedy works without proving the greedy choice property (many problems look greedy but aren't)
  • Sorting by the wrong criterion (end time vs start time vs duration matters)
  • Not considering edge cases where the greedy choice fails
  • Confusing greedy with DP — if you need to consider multiple previous choices, it's DP

When NOT to Use Greedy

  • When the optimal solution requires considering combinations of choices (use DP)
  • When local optimal choices conflict with global optimality (0/1 knapsack is NOT greedy)
  • When the problem requires exploring all possibilities (use backtracking)

Practice Problems

Compare With Other Patterns

Master Greedy

Build pattern recognition with interactive MCQs. Understand why to use Greedy, not just how.

Download LeetEye Free
Practice in LeetEye