Merge Restaurant Opening Hours Into Bookable Availability Windows
Last updated: November 29, 2026
Quick Overview
A restaurant partner can enter several opening slots for a day, and the slots may overlap or touch. Merge them into disjoint windows and answer whether the restaurant is open at a given minute.
Zomato
November 29, 20260
0
0 solved
A restaurant partner can enter several opening slots for a day, and the slots may overlap or touch. Merge them into disjoint windows and answer whether the restaurant is open at a given minute.
Restaurant listings on Zomato only show a restaurant as orderable when it is inside its opening hours, and partners often enter messy, overlapping slots. A phone screen uses this to check clean interval handling, half-open boundaries and a sensible query structure.
What the Interviewer Expects
- Sort slots by start time before merging
- Treat touching slots (close equals next open) as one window
- State that windows are half-open [open, close)
- Use binary search for the is-open query after merging
- Give O(n log n) build and O(log n) query complexity
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 support a slot that crosses midnight, such as 22:00 to 02:00?
- How would you handle a temporary closure that removes part of a window?
- If you receive millions of is-open queries per minute across restaurants, what would you precompute?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a list of (open, close) pairs in minutes from midnight with open < close. Output: sorted disjoint windows, plus is_open(t). I will treat each window as half-open [open, close) so a rest...
High-Level Design
Sort by start. Walk once, keeping the last merged window; if the next slot starts at or before the current end, extend the end, otherwise start a new window. Because the result is sorted and disjoint,...