Title isn't great, and I'm open to suggestions.
Here's my basic problem:
I have a set of appointments, each with a start time and end time.
Given that set, what I want is a new set of ranges [ start_time, end_time ]
for all periods where there are n
overlapping appointments.
So, for example, given the set (timestamps simplified to small numbers for readability)
[
[ 1, 3 ],
[ 2, 4 ],
[ 2, 4 ],
[ 5, 7 ],
[ 6, 8 ],
[ 7, 8 ]
]
...and assuming I want all ranges that have at least 3 different appointments occurring within them, the result should be
[
[ 2, 3 ],
[ 6, 7 ]
]
To make this a bit less abstract...
Imagine I run a 24-hour window-tinting service with 3 installers on staff at all times. On my website, I want to show all available installation times. So I need to hide any time ranges where I've already got 3 appointments scheduled.
Not necessarily asking anyone to write code – but if there's a well-known algorithm for this class of problem that someone could point me to, I'd appreciate it.
Thanks.
[EDIT] added javascript tag because i'll be implementing this in Node, but answers don't need to be in JS.
[EDIT 2] I'm looking for a pretty general solution, so let's say that appointments can start at any time (not normalized to hour or 30 minute chunks) and can be of any duration