Imagine you're a busy conference attendee trying to maximize your networking opportunities! You have a list of events happening over several days, and each event has a specific start day and end day.
You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.
Here's the challenge: You can attend any event i on any day d where startDayi โค d โค endDayi. However, you can only attend one event per day (no multitasking allowed!).
Goal: Return the maximum number of events you can attend.
This is a classic greedy scheduling problem that tests your ability to make optimal local decisions for a globally optimal solution.
Input & Output
Visualization
Time & Space Complexity
Sorting takes O(n log n), and heap operations for each event take O(log n)
Space for the heap to store occupied days
Constraints
- 1 โค events.length โค 105
- events[i].length == 2
- 1 โค startDayi โค endDayi โค 105
- Each event lasts at least 1 day