Most greedy algorithms follow this pattern:
Sort or organize the input (by end time, weight, value, etc.)
Initialize your solution (empty set, zero count, etc.)
For each item in order: if it fits your constraints, take it
Return the accumulated solution The sorting step is often the core idea. Different sort orders lead to different greedy strategies. The right order makes greedy work; the wrong order makes it fail. The constraint check in step catches conflicts early. Common bug: only checking constraints after building the full solution instead of at each step.