Maximum Number of Events That Can Be Attended
Signals to notice
Brute force first
Try all assignments of events to days — exponential. Each event-day pair is a choice. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
The key insight
Sort events by start day. For each day, add all events starting on that day to a min-heap (by end day). Attend the event ending soonest (pop heap). Skip expired events. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
What must stay true
On each day, attending the event with the earliest deadline maximizes future flexibility — it's the event you're most at risk of losing. Events with later deadlines can still be attended tomorrow. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Easy way to go wrong
Attending events in order of start day instead of deadline — an event starting early but ending late should be deferred if another event is about to expire. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.