CharlieDigital
4 hours ago
I'm not sure about the specifics of what Cal.com is trying to do, but interval trees [0] are a good fit and generally simplify a lot of the otherwise iterative or recursive logic for scheduling. There are some other related algorithms in 3D to calculate occulusion that can be used.
I have a practical writeup here as well that demonstrates pulling multiple calendars, building an interval tree, and then checking for overlaps/finding free slots [1]. It is possible to modify the algorithm so that the free slots are also tracked so no iteration is required to detect conflicts (trading space for time).
There are some other algorithms for bin-packing (calendar scheduling over a closed interval is just a bin-packing problem) that can also be used for this type of solving. Google OR-Tools, for example [2].
However, my sense is that interval trees or bin-packing solvers are what teams building schedulers really want, but teams building schedulers usually start with simple. Hope the Cal.com team sees this and gives it a go!
[0] https://en.wikipedia.org/wiki/Interval_tree
[1] https://chrlschn.dev/blog/2022/11/concurrent-processing-dotn...