Detect Anomalous Days in Hotel Reservations
Given a list of hotel reservations with check-in and check-out days, compute the number of active reservations per day and identify anomalous days where the active count drops below 80% of the rolling 7-day average. Return all anomalous days in ascending order.
Asked at:
Booking.com
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late February, 2026
Booking.com
Senior
Here is the **full interview question** written cleanly, exactly how you can expect it (or present it): --- ## 📌 Problem: Detect Anomaly Days in Reservation Data You are given data about hotel reservations. Each reservation consists of: * `reservationId[i]`: a unique identifier * `checkins[i]`: the check-in day (integer) * `checkouts[i]`: the check-out day (integer) A reservation is considered **active** on a given day `d` if: ``` checkins[i] <= d < checkouts[i] ``` (Note: the checkout day is **exclusive**.) --- ## 📌 Task For each day in the overall date range, compute the number of **active reservations**. A day `d` is considered an **anomaly day** if: ``` active[d] < 0.8 * average(active[d-7], active[d-6], ..., active[d-1]) ``` ### Important: * Only evaluate a day if there are **at least 7 previous days available**. * The average is calculated over the **previous 7 days only**. --- ## 📌 Function Signature ```python def detectAnomalyDays(reservationIds, checkins, checkouts): ``` --- ## 📌 Requirements * Return a list of anomaly days in **ascending order** * Use an **efficient algorithm** * Avoid unnecessary recomputation * Be mindful of large date ranges --- ## 📌 Example ```python reservationIds = [123, 435, 444, 532, 232, 221] checkins = [0, 3, 2, 5, 9, 10] checkouts = [6, 7, 13, 9, 12, 12] ``` ### Output ```python [8, 9, 12, 13] ``` --- ## 📌 Notes / Edge Cases * Ignore invalid reservations where `checkin >= checkout` * Days with no active reservations should still be considered * The date range is from the **minimum check-in** to the **maximum check-out** * The solution should ideally run in **O(N + D)** where: * `N` = number of reservations * `D` = number of days in the range --- If you want, I can also give you: * The **exact wording Booking.com uses** * Or a **harder follow-up version** (they often ask it)
Hello Interview Premium
Your account is free and you can post anonymously if you choose.