Nightly Calendar Revenue
MediumIntervals · Airbnb
Each reservation is [listing_id, start_day, end_day, nightly_price]. It occupies the nights start_day, start_day + 1, ..., end_day - 1: the guest checks out on end_day, so that night is not booked. Reservations may overlap, including on the same listing, and every reservation contributes independently.
For each day in dates, compute the total nightly_price of all reservations that occupy that night.
Return a list with one [day, revenue] pair per entry of dates, in the same order as dates. Dates are not necessarily sorted and may repeat. A night with no reservations has revenue 0.
Example 1
- Input:
- reservations = [['h1', 2, 5, 120], ['h2', 4, 6, 80], ['h1', 6, 8, 150]], dates = [4, 5, 6, 1]
- Output:
- [[4, 200], [5, 80], [6, 150], [1, 0]]
- Explanation
- Night 4 is inside both the first reservation (nights 2-4) and the second (nights 4-5), giving 200. Night 5 only has the second. On night 6 the second reservation has checked out and the third has started, so it is 150. Nobody is booked on night 1.
Example 2
- Input:
- reservations = [['a', 1, 3, 50], ['b', 1, 3, 50], ['a', 3, 4, 70]], dates = [3, 2, 3]
- Output:
- [[3, 70], [2, 100], [3, 70]]
- Explanation
- Night 2 is covered by the two 50-per-night reservations. Night 3 is their checkout day, so only the 70 reservation counts. The repeated query is answered again, in its original position.
Constraints
0 <= reservations.length <= 10^51 <= dates.length <= 10^50 <= start_day < end_day <= 10^91 <= nightly_price <= 10^40 <= dates[i] <= 10^9