KatInterview

Venue Hours Checker with Overnight and Multi-Window Schedules

Greedy & IntervalsAuto-graded · 27 test cases
MediumAuto-gradedGreedy & Intervalsintervalssimulationboundary-conditions

Last updated

Tests whether a venue is open at a given weekday and time, handling multiple daily windows, overnight shifts, and week-boundary wraparound.

Venue Hours Checker

A venue operates on a weekly schedule. Given that schedule and a specific day and time, determine whether the venue is currently open.

The schedule is defined by two pieces of information:

  • Active days: a list of weekday numbers on which the schedule applies. Days are numbered 0 through 6, where 0 is Monday and 6 is Sunday.
  • Time windows: a list of [open_time, close_time] pairs, where each time is [hour, minute] on a 24-hour clock. These windows apply identically on every active day.

Opening and Closing Rules

  • The opening minute is inclusive: the venue is considered open at exactly the opening time.
  • The closing minute is exclusive: the venue is considered closed at exactly the closing time.
  • If the opening time equals the closing time, the window covers no time at all (empty window).

Overnight Windows

A window crosses midnight when its opening time is later in the day than its closing time — for example, [22, 0] to [2, 0]. Such a window begins on the active day and ends in the early hours of the following calendar day.

A time that falls in the early morning (before the closing time) counts as open if the previous day is an active day and the overnight window from that previous day has not yet closed.

The week wraps around: Sunday (6) is followed by Monday (0), so a Sunday overnight window can cover early Monday morning.

Input Validation

Raise a ValueError for any of the following:

  • day is not an integer in [0, 6]
  • hour is not an integer in [0, 23]
  • minute is not an integer in [0, 59]
  • Any entry in active_days is not an integer in [0, 6]
  • Any window does not have exactly two time entries, or any time entry does not have exactly two integers within their valid ranges

Overlapping windows and windows listed in any order are both valid and must be handled correctly.

Constraints

  • 0 <= len(active_days) <= 7; each entry is an integer in [0, 6]
  • 0 <= len(windows) <= 100; each window is [[h1, m1], [h2, m2]]
  • 0 <= h1, h2 <= 23; 0 <= m1, m2 <= 59
  • 0 <= day <= 6, 0 <= hour <= 23, 0 <= minute <= 59
  • Invalid inputs raise ValueError

Examples

Example 1

Input: check_venue_open([0, 1, 2, 3, 4], [[[8, 0], [10, 0]]], 0, 9, 0)

Output: True

Example 2

Input: check_venue_open([0, 1, 2, 3, 4], [[[8, 0], [10, 0]], [[14, 0], [20, 0]]], 2, 12, 0)

Output: False

Example 3

Input: check_venue_open([4, 5], [[[22, 0], [2, 0]]], 4, 23, 0)

Output: True

Example 4

Input: check_venue_open([4, 5], [[[22, 0], [2, 0]]], 5, 1, 30)

Output: True

Example 5

Input: check_venue_open([6], [[[22, 0], [2, 0]]], 0, 1, 0)

Output: True

Hints

Hint 1

Convert every time to a single integer — total minutes since midnight — so you can compare times with a single comparison instead of juggling hours and minutes separately.

Hint 2

Handle the query day and the previous day independently. For the query day, check normal (non-overnight) windows and the start of overnight windows. For the previous day, check only overnight windows whose tail end covers the current early-morning time.

Hint 3

The week is circular: the day before Monday (0) is Sunday (6). Use modular arithmetic — `(day - 1) % 7` — to get the previous day without a special case.