Greedy

Make locally optimal choices that lead to a globally optimal solution.

4 Problems2-3 hours3 Medium1 Hard

Overview

Greedy algorithms make the locally best choice at each step. They work when the problem has the greedy choice property and optimal substructure.

Complexity Summary

Time Complexity

Usually O(n log n) for sorting + O(n) for sweep

Space Complexity

O(1) typically

Key Patterns & Techniques

Learn the core patterns in this topic. Each block explains when to use the pattern, the intuition behind it, and a compact code example.

1

Greedy Choice Property

Concept

local optimum leads to global optimum

Practice questions for this pattern
2

Sorting First

Concept

sort intervals, tasks, or items before making decisions

Practice questions for this pattern
3

Interval Scheduling

Concept

sort by end time for max non-overlapping intervals

Practice questions for this pattern
4

Jump Game

Concept

track the farthest reachable index

Practice questions for this pattern
5

Contrast with DP

Concept

use greedy when provably correct; use DP otherwise

Practice questions for this pattern
6

Exchange Argument

Concept

proof technique: show swapping improves or maintains solution

Practice questions for this pattern
DSA Practice Online - 150+ Coding Interview Questions | LeetCode Alternative | InstaMock - AI Mock Interview