Stage 1 · Code
Greedy Algorithms
Interval Scheduling
Weighted and unweighted interval scheduling variants.
Unweighted (Activity Selection)
Maximize count of non-overlapping intervals. Earliest finish time greedy works. O(n log n) for sort.
Weighted Interval Scheduling
Each interval has value/weight. Maximize total weight of non-overlapping intervals. Greedy fails. Use DP: sort by finish, for each interval find previous compatible (binary search). DP[i] = max(weight[i] + DP[prev(i)], DP[i-1]).
Interval Partitioning
Schedule all intervals using minimum number of resources (rooms). Equivalent to finding max concurrent intervals. Greedy: sort by start time, assign each to first available room (min-heap of room end times).
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.