easy +8 pts

Time Slot Generator

Generate non-overlapping time slots of a fixed duration within a given window.

Implement the function `generate_time_slots(start: str, end: str, slot_minutes: int) -> list[str]`. The function receives start and end times as strings in 24-hour format 'HH:MM' (e.g., '09:00'). It returns a list of strings representing all possible consecutive time slots of duration `slot_minutes` minutes that fit exactly between `start` and `end`. Each slot is represented as 'HH:MM-HH:MM' (e.g., '09:00-09:30'). Slots must not overlap and must cover the entire interval from `start` to `end`. The first slot starts at `start`. If the total interval length is less than `slot_minutes` minutes, return an empty list. `slot_minutes` is a positive integer. The result should be in chronological order.

Constraints

1 <= slot_minutes <= 1440. Input times are valid 'HH:MM' (00:00 to 23:59). The end time is always later than the start time on the same day.

Example

>>> generate_time_slots('09:00', '10:00', 30)
['09:00-09:30', '09:30-10:00']
>>> generate_time_slots('09:00', '10:00', 45)
['09:00-09:45']
>>> generate_time_slots('09:00', '09:30', 30)
['09:00-09:30']
>>> generate_time_slots('09:00', '09:29', 30)
[]
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Convert 'HH:MM' to minutes since midnight using int(part).
Use a loop that increments the current time by slot_minutes until it reaches the end time.
Format each slot using f"{hh:02d}:{mm:02d}" for both endpoints.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.