<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>]</code>. Every event <code>i</code> starts at <code>startDay<sub>i</sub></code><sub> </sub>and ends at <code>endDay<sub>i</sub></code>.</p>

<p>You can attend an event <code>i</code> at any day <code>d</code> where <code>startTime<sub>i</sub> &lt;= d &lt;= endTime<sub>i</sub></code>. You can only attend one event at any time <code>d</code>.</p>

<p>Return <em>the maximum number of events you can attend</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/02/05/e1.png" style="width: 400px; height: 267px;" />
<pre>
<strong>Input:</strong> events = [[1,2],[2,3],[3,4]]
<strong>Output:</strong> 3
<strong>Explanation:</strong> 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.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> events= [[1,2],[2,3],[3,4],[1,2]]
<strong>Output:</strong> 4
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= events.length &lt;= 10<sup>5</sup></code></li>
	<li><code>events[i].length == 2</code></li>
	<li><code>1 &lt;= startDay<sub>i</sub> &lt;= endDay<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
</ul>

import heapq

class Solution:
    def maxEvents(self, events: List[List[int]]) -> int:
        # Sort events by start day
        events.sort(key=lambda x: x[0])
        
        # Priority queue to store end days of current events
        min_heap = []
        
        # Initialize variables
        i = 0  # Index for iterating through events
        day = 0  # Current day
        count = 0  # Number of attended events
        
        # Iterate through the days
        while i < len(events) or min_heap:
            # If the heap is empty or the current day is before the next event's start day
            if not min_heap:
                day = events[i][0]
            
            # Add all events that start on the current day to the heap
            while i < len(events) and events[i][0] == day:
                heapq.heappush(min_heap, events[i][1])
                i += 1
            
            # Remove events that have ended before the current day
            while min_heap and min_heap[0] < day:
                heapq.heappop(min_heap)
            
            # Attend the event that ends the earliest
            if min_heap:
                heapq.heappop(min_heap)
                count += 1
            
            # Move to the next day
            day += 1
        
        return count

# Example usage:
solution = Solution()
events = [[1,2],[2,3],[3,4]]
print(solution.maxEvents(events))  # Output: 3

events = [[1,2],[2,3],[3,4],[1,2]]
print(solution.maxEvents(events))  # Output: 4
64900