I was asked this at an interview, I was able to implement it but there were edge cases that I didn't think through clearly and failed.
*Google Calendar, Outlook, iCal has been banned from your company! So an intrepid engineer has decided to roll their own implementation. Unfortunately one major missing feature is the ability to find out what time slots are free for a particular individual.
Given a list of time blocks where a particular person is already booked/busy, a start and end time to search between, a minimum duration to search for, find all the blocks of time that a person is free for a potential meeting that will last the aforementioned duration.
Given: starttime, endtime, duration, meetingslist -> suggestedmeetingtimes
Let's assume we abstract the representation of times as simple integers, so a valid time is any valid integer supported by your environment. Here is an example input:
meetingslist: [3,20], [-2, 0], [0,2], [16,17], [19,23], [30,40], [27, 33]
starttime: -5
endtime: 27
minduration: 2
expected answer:
freetime: [-5, -2], [23,27]*