Earliest Meeting Start on a 24-Hour Clock
Problem statement
Work runs all day and night, so a meeting can start late in the evening and end after midnight. Times use a 24-hour clock in "HH:MM" form, from "00:00" to "23:59", and every time is a whole minute.
You are given the meetings that already happen every day. Each meetings[i] = [from, to] uses every minute from from to to, including both of them. If to is earlier in the day than from, the meeting runs past midnight and ends at to the next day.
You want to add one new meeting that lasts duration minutes. If it starts at time t, it ends at duration minutes after t and uses every minute from t to its end, including both. It may run past midnight into the next day.
The new meeting must not share any minute with another meeting. So if a meeting ends at 09:00, the next meeting can start at 09:01 at the earliest. Because the meetings happen every day, the part of the new meeting after midnight must also avoid the meetings at those times.
Return the earliest start time, at or after start and no later than "23:59", at which the new meeting fits. Return it in "HH:MM" form. If no such start time exists, return "-1".
The meetings can be given in any order and can overlap each other.
Function
earliestMeetingStart(meetings: String[][], start: String, duration: int) → StringExamples
Example 1
meetings = [["09:00","10:00"],["10:30","11:00"]]start = "09:30"duration = 15return = "10:01"From 09:30 to 10:00 the first meeting is running. It still uses 10:00, so the earliest free start is 10:01.
A 15-minute meeting from 10:01 ends at 10:16, which is before the meeting at 10:30. So the answer is "10:01".
Example 2
meetings = [["02:30","03:00"],["20:00","22:00"]]start = "21:00"duration = 240return = "22:01"The meeting from 20:00 to 22:00 blocks every start up to 22:00.
A 4-hour meeting from 22:01 runs past midnight and ends at 02:01 the next day. That is before the 02:30 meeting, so it fits and the answer is "22:01".
Example 3
meetings = [["01:00","02:00"],["21:00","22:00"]]start = "20:00"duration = 240return = "-1"- A start from
20:00to22:00runs into the meeting from21:00to22:00. - A start from
22:01to23:59ends at02:01or later the next day. The meetings repeat every day, so it runs into the meeting from01:00to02:00.
No start from 20:00 to 23:59 works, so the answer is "-1", even though a start such as 16:00 would fit.
Example 4
meetings = [["22:00","01:00"]]start = "00:30"duration = 30return = "01:01"The meeting from 22:00 to 01:00 runs past midnight, so it also uses every minute from 00:00 to 01:00.
The first free start at or after 00:30 is 01:01, and a 30-minute meeting from there ends at 01:31.
Constraints
0 <= meetings.length <= 1000meetings[i].length == 2- Every time in
meetingsandstartis a string in"HH:MM"form from"00:00"to"23:59". meetings[i][0] != meetings[i][1]1 <= duration <= 1439