You are given an array of events where events[i] = [startDayi, endDayi]. Every event i starts at startDayi and ends at endDayi.
You can attend an event i at any day d where startDayi <= d <= endDayi. You can only attend one event at any time d.
Return the maximum number of events you can attend.
Input: events = [[1,2],[2,3],[3,4]]
Output: 3
Explanation: You can attend all the three events.
One way to attend them all is as shown.
Attend the first event on day 1.
Attend the second event on day 2.
Attend the third event on day 3.
Input: events= [[1,2],[2,3],[3,4],[1,2]]
Output: 4
The brute force approach involves tracking the days individually and checking which events can be attended day-by-day. For each day, check all events to see which event can finish by the current day - if none can, proceed to the next day. This method aims to maximize the number of events attended by linearly scanning available events day-by-day.
n is the number of events and d is the range of days. Typically infeasible for large inputs.d is the range of days for marking attended days.The greedy approach utilizes a priority queue to efficiently choose events in a way that maximizes the number of days available for future events. Sort the events by their start date and use a priority queue to keep track of events that can be attended each day - this allows attending events that end the earliest if multiple events are possible on the same day.
n is the number of events due to sorting and priority queue operations.n is the number of events for the priority queue.