Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meeting Conflict algorithms

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

like image 258
sam_33 Avatar asked Feb 04 '11 20:02

sam_33


People also ask

What does conflicting appointments found mean?

It means that you have two events or appointments at the same time, so it creates a problem.

What is a calendar conflict?

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.


2 Answers

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.

like image 89
2 revs Avatar answered Nov 03 '22 00:11

2 revs


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;
}
like image 21
Bill the Lizard Avatar answered Nov 03 '22 01:11

Bill the Lizard