Here is how we will implement this feature:
BST class: First, we will implement a simple BST class with a constructor, an insert function, and an addNode function.
constructor: The default constructor initializes the root of the node as null. Later on, this root will be of type Node.
insert() function: This function takes in the start and end timing of meetings and creates a new node. If the root is null, then the new node will become the root. Otherwise, the recursive helper function addNode will be called. The return type of this function is Boolean, as we will use it to determine if the node was added successfully.
addNode() function: This recursive helper function has two inputs: currentNode, which is initially the root node, and the newNode to be added. We will check if the newNode starts before the currentNode ends; this shows that there is no conflict up to this point. This means we will have to call the recursive function again to check for a conflict in the right child of the currentNode. If the previous check does not pass, we will check if the newNode starts after the currentNode and similarly call the recursive function for the left subtree if the check passes. If both of these conditions fail, this means that the new meeting overlaps with an existing meeting. Therefore, we will return false.
checkMeeting() function: We initialize the BST with the user’s scheduled meetings in this function. Then, we will add the new meeting and return the result.