Hotel stay email schedule with booking changes
A hotel wants to send each guest a set of emails around their stay. Write the code that produces the full email schedule.
Input
-
reservations: a list of objects withguest_name(string, unique),room_type(string),check_in_day(integer) andstay_length(integer number of nights, 0 or more). -
touchpoints: a map from a timing key to an email label. A key is one of:-
"start": the check-in day. -
"end": the check-out day, which ischeck_in_day + stay_length. - A signed integer string such as
"-3"or"+1": that many days from the check-in day.
-
Part 1. Implement build_schedule(reservations, touchpoints) -> List[str]. Return one line per (reservation, touchpoint) pair, formatted "<day>: [<label>] <guest_name>" and sorted by day. When several emails fall on the same day, keep reservations in input order and, within one reservation, touchpoints in the order given.
Part 2. Some room types have their own touchpoints. Add an optional room_touchpoints map from room type to a touchpoint map. A guest's touchpoints are the defaults plus their room type's entries. On a key collision the room type's label wins.
Part 3. Bookings change. Implement build_schedule_with_changes(reservations, touchpoints, changes). Each change has a day, a guest_name, and an action of "cancel" or "modify". A modify may carry a new check_in_day, stay_length or room_type. Emails dated before the change day were already sent and stay in the schedule. From the change day on, only emails for the new booking are sent, and none after a cancellation. Ignore changes for unknown or already cancelled guests.
Constraints
- Up to 10^4 reservations and 20 touchpoints each.
- Days are integers and may be negative after applying an offset.
Example
reservations = [
{"guest_name": "Ana", "room_type": "suite", "check_in_day": 10, "stay_length": 3},
{"guest_name": "Ben", "room_type": "double", "check_in_day": 4, "stay_length": 6},
]
touchpoints = {"-2": "Prepare", "start": "Welcome", "end": "Thank you"}
Part 1:
2: [Prepare] Ben
4: [Welcome] Ben
8: [Prepare] Ana
10: [Welcome] Ana
10: [Thank you] Ben
13: [Thank you] Ana
Example with changes
changes = [
{"day": 9, "guest_name": "Ana", "action": "modify", "check_in_day": 12},
{"day": 3, "guest_name": "Ben", "action": "cancel"},
]
Part 3:
2: [Prepare] Ben
8: [Prepare] Ana
10: [Prepare] Ana
12: [Welcome] Ana
15: [Thank you] Ana
Interviewers usually reveal the parts one at a time.
Reconstructed from the reported question; details may differ from what interviewers ask.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
