Drill

ProblemsPython › events

Which slot does this time fall into

easyeventsPython

A booking window is split into equal-length slots. Given a time in minutes, return the slot number or -1 if it does not belong.

slot_index(time_minutes: int, window_start: int, slot_minutes: int) → int

Solve it in the editor →

Where you start

def slot_index(time_minutes: int, window_start: int, slot_minutes: int) -> int:
    

Worked examples

CallResult
slot_index(600, 540, 30)2
slot_index(700, 540, 30)5
slot_index(1331, 540, 30)-1
slot_index(500, 540, 30)-1

Hint

Check the bounds first, then divide.

Reference solution in Python
def slot_index(time_minutes: int, window_start: int, slot_minutes: int) -> int:
    if time_minutes < window_start or time_minutes >= window_start + slot_minutes * 8:
        return -1
    return (time_minutes - window_start) // slot_minutes

The same problem in another language

More events problems in Python