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.
ShiftTotal(shifts: list<Shift>) → 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.
Where you start
public int ShiftTotal(List<Shift> shifts) {
}
Worked examples
| Call | Result |
|---|---|
ShiftTotal(new List<Shift> { new Shift(480, 900), new Shift(900, 1080) }) | 600 |
ShiftTotal(new List<Shift> { new Shift(0, 1440) }) | 1440 |
ShiftTotal(new List<Shift> { }) | 0 |
ShiftTotal(new List<Shift> { new Shift(600, 600) }) | 0 |
Hint
Sum of (end - start).
Reference solution in C#
public int ShiftTotal(List<Shift> shifts) {
int total = 0;
foreach (var s in shifts) total += s.End - s.Start;
return total;
}