Find Oversold Night Ranges per Room Type From Bookings
Last updated: November 29, 2026
Quick Overview
Given the number of rooms per room type and a list of bookings (room_type, check_in, check_out) with integer nights and exclusive check-out, return for each room type the maximal contiguous night ranges where confirmed bookings exceed capacity.
Agoda
November 29, 20260
0
0 solved
Given the number of rooms per room type and a list of bookings (room_type, check_in, check_out) with integer nights and exclusive check-out, return for each room type the maximal contiguous night ranges where confirmed bookings exceed capacity.
Agoda sells allotments that can drift out of sync with a hotel's channel manager, so detecting overbooked nights is a real operational concern. Interviewers in the technical screen use this to check sweep-line reasoning, correct handling of half-open intervals, and merging consecutive bad nights into ranges instead of listing nights one by one.
What the Interviewer Expects
- Model each booking as a half-open interval [check_in, check_out) and emit +1/-1 events
- Process events per room type in sorted order, tracking active count against capacity
- Open a range when the count first exceeds capacity and close it when it drops back to capacity or below
- Avoid iterating night by night when stays are long; cost should depend on bookings, not on calendar length
- Handle zero-length or invalid bookings and room types missing from the capacity map
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you also report the peak overbooking amount within each range?
- Bookings arrive continuously; how would you answer "is night d oversold for room type r" after each new booking in O(log n)?
- What changes if a booking can be moved to an upgraded room type when its own type is full?
- How would you shard this across thousands of hotels in a batch job?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Nights are integers, check-out is exclusive, so a booking ("DLX", 1, 5) occupies nights 1 to 4. A night is oversold when active bookings for that type exceed capacity[type]. Output maps each room ...
High-Level Design
Group bookings by room type. For each type, build a sparse difference map: +1 at check-in, -1 at check-out. Walking the sorted event days gives the active count on each segment between consecutive...