...

/

Feature #3: Check if Meeting is Possible

Feature #3: Check if Meeting is Possible

Description

For this feature, we want to program a function that will let User A know if it is possible to schedule a meeting with User B or not. This decision will be made based on User B’s meeting schedule. If the new meeting’s time overlaps with an existing meeting in User B’s schedule, then the new meeting can not be scheduled.

Note: We will assume that User A is already free during the time of the new meeting, so no checks for this user are needed.

You will be given a list of start and end times of User B’s scheduled meetings, which are non-overlapping. Additionally, you will be given the start and end times for the proposed meeting, which we need to verify is schedulable.

Suppose that the list of timings is [[1, 3], [4, 6], [8, 10], [10, 12], [13, 15]], and the new meeting is [7, 8]. In this example, you can see that the new meeting does not overlap with any existing meetings. Therefore, it can be scheduled, and the output will be True. Now, consider if the new meeting had been [9, 11]. It would have overlapped with [8, 10] and [10, 12]. Therefore, the output would have been False.

Note: For simplicity, we are mapping the military timing to integers in the input. So, for example, 8:00 will be denoted by 8 in the code.

Solution

This feature can be implemented by brute force traversal. However, we can make it more efficient using a Binary Search Tree (BST). The main advantage is that we can insert all the meetings in a BST first, and then check if the new meeting can also be inserted without any clash. Placing the meetings in a BST in sorted order lets us verify whether the new meeting can be added in O(log(n) ...

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy