core practice · coding problem
Activity selection greedy
Activities by end time: [1,4],[3,5],[0,6],[5,7],[8,9],[5,9]. Max non-overlapping count?
The mechanism
A greedy algorithm always picks the choice that looks best right now. It only gives the right answer when the problem has a structure (an exchange argument) that proves local choices add up correctly. When they do not, greedy quietly returns wrong answers.
Expected evidence
3 activities: [1,4], [5,7], [8,9].
Try this drill in the practice workspace →
Hints when you need them
- Sort by finish time.
- Take next compatible activity greedily.