You're a restaurant manager who's job is to find available time windows for seating N number of guest(s). Lets assume your restaruant is specified in the following way:
restaurant = {
'restaurant_start': 9,
'restaurant_end': 22,
'capacity': 5,
'reservations': [
{'start': 10, 'end': 14, 'ppl': 3},
{'start': 11, 'end': 13, 'ppl': 2},
{'start': 13.5, 'end': 15, 'ppl': 1},
{'start': 16, 'end': 20, 'ppl': 2}
]
}
Where `restaurant_start` and `restaurant_end` are the open and close times of the resturant, `capacity` is the maximum number people the restaurant can fit at any point, and `reservations` are existing reservations w/ guests (e.g `ppl` is the number of customers who are already at the restaurant at that time interval).
Write an algorithm that can output all available time intervals for seating an input N guests from restaurant open to close (e.g [[9,11],....]]). Assume your input to the function is in the format of the restaurant dictionary object specified above along with a parameter N indicating the number of people to seat.
Anyone know how to solve this question? I had no idea what to do and had to ask the interviewer if I could simplify the problem to not worry about fractional start and end times (e.g [13.5, 14]). Went down the route of a histogram counting approach to find the time ranges that had capacity for seating but could not finish an implementation...and even if I did finish it it wouldn't work for fractional start and end times. Is there anything on leetcode that's similar to this?
Comments (7)


