<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:
        # Get a list of events sorted, then reverse them so they can be picked out
        # for any given day
        h = []
        events.sort()
        events.reverse()
        # Gotcha
        daylast = max([event[1] for event in events])
        day = events[-1][0]
        count = 0
        while day <= daylast:
            # print(f"{day}, {len(events)}")
            # get all events that begin today
            while events and events[-1][0] <= day:
                event = events[-1]
                heapq.heappush(h, (event[1], event[0]))
                events.pop()
            # pick the one that ends first, when there are records
            # in the heap.
            if not h and events:
                # No records in heap
                # print(f"Empty {day}, next {events[-1][0]}")
                day = events[-1][0]
                continue
            elif not h and not events:
                # all events are done.
                # print(f"Break at {day}")
                break
            while h:
                e = heapq.heappop(h)
                e_end = e[0]
                e_start = e[1]
                if e_end < day:
                    # print(f"Skip {(e_start, e_end)}")
                    continue
                # print(f"{day}, {(e_start, e_end)}")
                day = max(day + 1, e_start + 1)
                count += 1
                break
        return count
53200