I'm going to be as clear as I can.

I have an event that have two times, start and end. (Times are in 24h format)
For example, this event starts at 8, and finishes at 12.

With this event, I have a list of person with their work schedule.
Here's an example :

* Person 1 : From 8:00 to 10:00
* Person 2 : From 10:00 to 12:00
* Person 3 : From 6:00 to 15:00
* Person 4 : From 8:00 to 9:00
* Person 5 : From 9:30 to 12:00

Now, I need to know how many people, at minimum, I have through the whole event.

In my case, it will be **2**, because :

* Person 1 & Person 2 complement each other
* Person 3 will always be present
* There is a gasp between person 4 & 5, between 9:00 and 9:30, so during this time, no one between Person 4 & 5 will be present.

If I explain this with times :

* From 8:00 to 9:00 : Person 1, 3, 4
* From 9:00 to 9:30 : Person 1, 3
* From 9:30 to 10:00 : Person 1, 3, 5
* From 10:00 to 12:00 : Person 2, 3, 5

Most of the time, the event will have 3 person, but the lowest if 2.

How can I get this number using an algorithm, I can't make my mind with this.

I thought about converting the time in minutes (I won't go under the minute), set the range at the event times (from 8\*60 to 12\*60), and add each person presence as a new range, and then count for each minutes, how many slice there is (1 slice = 1 person). But I feel this isn't efficient, because I will have to count the slices for 4\*60 minutes :/ (from 8 -> 12).

How would you do ?