I had a interview today and was asked to check whether two meeting conflicts with each other or not. Each meeting has start time and end time.
I tried to answer the question but not that specific..can somebody throw some idea?
bool IsConflict(Datetime s1, Datetime e1, Datetime s2, Datetime e2)
should return true if Conflict is there and false if no conflict.
E.g
True if:
(s1, e1)= 8,10
(s2, e2) = 9, 11
(s1, e1)= 7,10
(s2, e2) = 8, 9
(s1, e1)= 8,11
(s2, e2) = 9, 11 and so on
It means that you have two events or appointments at the same time, so it creates a problem.
What are scheduling conflicts? A scheduling conflict in the workplace is when you have two tasks or events vying for your time and attention simultaneously. It is also a situation in which a team member is assigned two tasks or double shifts at the same time.
This is basic interval algebra, see my answer here for more details, but the code would look like this:
bool IsConflict(Datetime s1, Datetime e1, Datetime s2, Datetime e2)
{
return (s1 < e2) && (e1 > s2);
}
I am assuming that two meetings where one start where the other ends are not in conflict.
In the simple case of two intervals I think this will work (untested pseudocode ahead):
bool IsConflict(Datatime s1, Datatime e1, Datatime s2, Datatime e2) {
if( s1 < s2 ) {
// meeting 1 starts first
if( e1 > s2 ) return true; // overlap
}
else {
// meeting 2 starts first
if( e2 > s1 ) return true; // overlap
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With