Earliest Time to Schedule a Meeting
Problem statement
You are given an array of strings schedules. Each string has the form "<name> <activity> <start> <end>", for example "Alex work 01:00 13:30". It means that the person name is busy with activity from start to end, and both endpoints are included. Times use the 24-hour HH:MM format. One person can have several entries, and the entries can belong to different people.
A day is made of the minutes 00:00, 00:01, ..., 23:59. An entry blocks every minute from start through end. A meeting of length k that starts at minute s uses the k minutes s, s + 1, ..., s + k - 1. It must start and finish on the same day, so its last minute is 23:59 at the latest.
Everyone who appears in schedules must attend, so no minute of the meeting can be blocked by any entry. Return the earliest possible start time as a string in HH:MM format, or "-1" if no start time works.
Function
earliestMeetingTime(schedules: String[], k: int) → StringExamples
Example 1
schedules = ["Alex work 01:00 13:30","Sam sleep 00:00 08:00","Alex lunch 13:46 14:00"]k = 15return = "13:31"Together the entries block 00:00 through 13:30 (Sam's sleep overlaps Alex's work), then 13:46 through 14:00. Because 13:30 itself is blocked, the first free minute is 13:31. The minutes 13:31 through 13:45 are exactly 15 free minutes, so the meeting starts at "13:31".
Example 2
schedules = ["Alex work 01:00 13:30","Sam sleep 00:00 08:00","Alex lunch 13:46 14:00"]k = 16return = "14:01"The gap from 13:31 through 13:45 has only 15 minutes, one too few. The next free minute after Alex's lunch is 14:01, and the rest of the day is free, so the answer is "14:01".
Example 3
schedules = ["Ana meeting 00:00 23:00"]k = 60return = "-1"The only free minutes are 23:01 through 23:59, which is 59 minutes. A 60-minute meeting would have to end after 23:59, so no start time works and the answer is "-1".
Constraints
1 <= schedules.length <= 10^4- Each
schedules[i]isname,activity,start, andendseparated by single spaces. nameandactivityeach have1to10English letters.startandendare valid times from00:00to23:59inHH:MMformat, andstartis not later thanend.1 <= k <= 1440