You're writing the "find a time" button of a calendar app. events is a log of edits, in order, each a string
"<name> <action> <start> <end>" e.g. "maya busy 09:00 10:29"
- Everyone named in the log must attend (names are case-sensitive).
<start>and<end>are"HH:MM"times withstart <= end, covering every minute fromstartthroughend, both included.<action>isbusyorfree(e.g. a cancelled meeting). Later edits override earlier ones.
Implement earliest_slot(events: list[str], k: int) -> str | None: the start of the earliest run of k consecutive minutes free for everyone, ending by 23:59, or None.
events = [
"maya busy 09:00 10:29",
"raj busy 10:45 11:59",
"maya busy 00:00 08:59",
"raj free 11:00 11:59",
]
earliest_slot(events, 15) # "10:30" (10:30-10:44 is free for both)
earliest_slot(events, 16) # "11:00" (raj freed 11:00-11:59)
earliest_slot(["ana busy 00:00 23:58"], 1) # "23:59"
earliest_slot(["ana busy 00:00 23:58"], 2) # None
earliest_slot([], 1440) # "00:00"
Up to 2,000 events; 1 <= k <= 10**6.
Show hint
The day has only 1440 minutes. Keep a boolean array per person, apply the edits in order, then scan the day once counting the current run of minutes free for all.