Problems › Python › scheduling
Total minutes scheduled
A weekly grid lists every shift as a start and end in minutes past midnight. Add up the committed hours.
- A shift always ends after it starts.
- An empty grid is an empty week: zero minutes.
shift_total(shifts: list<Shift>) → int
Where you start
def shift_total(shifts: list[Shift]) -> int:
Worked examples
| Call | Result |
|---|---|
shift_total([Shift(start=480, end=900), Shift(start=900, end=1080)]) | 600 |
shift_total([Shift(start=0, end=1440)]) | 1440 |
shift_total([]) | 0 |
shift_total([Shift(start=600, end=600)]) | 0 |
Hint
Sum of (end - start).
Reference solution in Python
def shift_total(shifts: list[Shift]) -> int:
return sum(s.end - s.start for s in shifts)