Link: https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/
Solution:
Topics: heap, sorted order, greedy, simulation
Intuition
Extremely tricky problem. The key insight is that we must iterate over all possible days, because conceivably we can attend a different event on each day. Choosing which event is the tricky part. Basically, if an event starts on a particular day, we add it’s end day to a min_heap because we want to prioritize events that end sooner, since there is less opportunity to attend them.
We must sort events by start day and then iterate over days, all the while moving a pointer for events when a start day is reached.
Implementation
Visual