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
Coding & Algorithms
Software Engineer
Zomato
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Interval merging
Sorting
Binary search
Boundary conditions
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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,...


Submit Your Answer
Markdown supported

Related Questions