Feature #5: Find Common Meeting Times
In this lesson, we will implement the "Find common meeting times" feature of the Google calendar project.
We'll cover the following...
Description
For the final part of this project, we want to implement a feature that lets us see when two users are busy at the same time. We will be given the meeting schedule of two users, and we have to find all the overlapping meetings to determine when both of them are unavailable.
We will also assume that each user’s schedule is free of conflicting meetings, meaning their schedules are non-overlapping. Moreover, the meetings have been already sorted based on their starting time.
Let’s say that we are given the following pairs of meeting schedules: [[1, 3], [5, 6], [7, 9]]
and [[2, 3], [5, 7]]
. In this example, we can see that both of the users will be busy at the following times: [[2, 3], [5, 6]]
.
Take a look at the illustration given below:
TO BE DELETED
Description
For the final part of this project, we want to implement a feature that lets us see when two users are busy at the same time. We will be given the meeting schedule of two users, and we have to find all the overlapping meetings to determine when both of them are unavailable.
We will also assume that each user’s schedule is free of conflicting meetings, meaning their schedules are non-overlapping. Moreover, the meetings have been already sorted based on their starting time.
Let’s say that we are given the following pairs of meeting schedules: {{1, 3}, {5, 6}, {7, 9}}
and {{2, 3}, {5, 7}}
. In this example, we can see that both of the users will be busy at the following times: {{2, 3}, {5, 6}}
.
Take a look at the illustration given below:
Note: For simplicity, we are mapping the military timing to integers in the input. So, for example,
8:00
will be denoted by8
in the code.
Solution
Here is how we will implement this feature:
-
We will use two indices,
i
andj
, to traverse both of the meeting schedules,meetings_a
andmeetings_b
, respectively. -
The indices
i
andj
will both be zero at the beginning. -
Next, we will check if
meetings_a[i]
andmeetings_b[j]
overlap by comparing the start and end times. -
If the times overlap, the overlapping time interval will be added to the resultant list.
-
Otherwise, we will keep incrementing the indices depending upon the end time of the next meeting. This means that ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy