Drill

ProblemsC# › events

Which slot does this time fall into

easyeventsMathC#

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.

SlotIndex(timeMinutes: int, windowStart: int, slotMinutes: int) → int

C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

public int SlotIndex(int timeMinutes, int windowStart, int slotMinutes) {
    
}

Worked examples

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

Hint

Check the bounds first, then divide.

Reference solution in C#
public int SlotIndex(int timeMinutes, int windowStart, int slotMinutes) {
    if (timeMinutes < windowStart || timeMinutes >= windowStart + slotMinutes * 8) return -1;
    return (timeMinutes - windowStart) / slotMinutes;
}

The same problem in another language

More events problems in C#