Find Time Windows When At Least K Businesses Are Open

Last updated: November 29, 2026

Quick Overview

Given each business's open hours as a list of [start, end) minute intervals within the week (a business's own intervals may overlap), return the maximal time windows during which at least k distinct businesses are open simultaneously.

Yelp
Coding & Algorithms
Software Engineer
Yelp
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given each business's open hours as a list of [start, end) minute intervals within the week (a business's own intervals may overlap), return the maximal time windows during which at least k distinct businesses are open simultaneously.

Yelp's Open Now filter and neighborhood insights depend on reasoning about business hours, which are messy: split shifts, overlapping entries from duplicate data sources, and late night closings. The interviewer is testing a sweep line over events and whether you notice that one business must not be counted twice.

What the Interviewer Expects
  • Merge each business's own intervals before counting
  • Build +1 and -1 events and sweep in time order
  • Process all events at the same timestamp together to get half open semantics right
  • Emit maximal windows and do not split them at boundaries where the count stays at or above k
  • O(N log N) time for N intervals
Key Topics to Cover
sweep line
intervals
event sorting
merge intervals
business hours
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 handle hours that cross midnight on Sunday into Monday?
  • How would you answer many queries for different k values efficiently?
  • What changes if you also need the list of businesses open in each window?
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: schedules, a list where each element is one business's list of (start, end) pairs in minutes since Monday 00:00, half open. Output: sorted list of (start, end) windows where the number of...

High-Level Design

Two steps. First, merge each business's own intervals, because partner feeds often send overlapping duplicates and a business open twice is still one business. Second, sweep: add +1 at each start and ...


Submit Your Answer
Markdown supported

Related Questions