Problem · Intervals

Meeting Assistant

Learn this problem
MediumSnowflakeINTERNOA
See Snowflake hiring insights

Problem statement

Implement a simple meeting assistant. A list of strings, events[n], in the form "<person_name> <action> <start> <end>" is provided where person_name performs action from start to end, both inclusive. Times are formatted HH:MM. Find the earliest time in the day, from "00:00" to "23:59", when all people mentioned in at least one event are available for a meeting of k minutes. Report the answer as "HH:MM" or the string "-1" if it is not possible.

Function

getEarliestMeetTime(events: String[], k: int) → String

Complete the function getEarliestMeetTime in the editor below.

getEarliestMeetTime takes the following arguments:

  1. 1. String events[n]: event descriptors
  2. 2. int k: meeting duration

Returns

string: the earliest time for the meeting or "-1" if it is not possible

Examples

Example 1

events = ["Alex sleep 00:00 08:00", "Sam sleep 07:00 13:00", "Alex lunch 12:30 13:59"]k = 60return = "14:00"
Alex is not available until 8:00. After that, Sam is not available until 13:00. Then Alex is busy until 13:59. Return the earliest time they are both available, "14:00".

Example 2

events = ["sam sleep 12:00 23:59", "alex sleep 00:00 13:00"]k = 1return = "-1"
There is no time when both are free. 😞

Example 3

events = ["sam sleep 12:00 18:59", "alex gaming 00:00 11:00"]k = 60return = "19:00"
Alex plays games from 00:00 until 11:00. If the meeting starts at 11:01, it ends at 12:01. Sam is asleep from 12:00 to 18:59.

Constraints

  • 1 ≤ n ≤ 105
  • 1 ≤ length of events[i] ≤ 40
  • 1 ≤ k ≤ 1440
  • It is guaranteed that the number of people is less than 5000.
  • It is guaranteed that no person's events overlap.
  • More Snowflake problems

    drafts saved locally
    public String getEarliestMeetTime(String[] events, int k) {
        // write your code here
    }
    
    events["Alex sleep 00:00 08:00", "Sam sleep 07:00 13:00", "Alex lunch 12:30 13:59"]
    k60
    expected"14:00"
    checking account