I have a set of appointments on a specific work day that goes from 8am to 6pm:
Appointment 1: 9am-11am
Appointment 2: 2pm-5pm
I am looking for an efficient way to locate the free time. So in this case, the available time would be:
8am-9am
11am-2pm
5pm-6pm
So I have an TimeBlock class
class TimeBlock {
public DateTime start
public DateTime end
}
var appointments = new List<TimeBlock>();
var freeTimeBlocks = new List<TimeBlock>();
' add appointments
appointments.Add(new TimeBlock{start...
appointments.Add(new TimeBlock{start...
I am looking for an efficient way to find free time, because the algorithm will run on a pretty big data set.
Try this, it assumes there’s no overlapping appointments: