Drill

ProblemsC++ › scheduling

Total minutes scheduled

easyschedulingArraysIntervalsC++

A weekly grid lists every shift as a start and end in minutes past midnight. Add up the committed hours.

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.

Solve it in Python →

Where you start

int shiftTotal(std::vector<Shift> shifts) {
    
}

Worked examples

CallResult
shiftTotal(std::vector<Shift>{Shift{480, 900}, Shift{900, 1080}})600
shiftTotal(std::vector<Shift>{Shift{0, 1440}})1440
shiftTotal(std::vector<Shift>{})0
shiftTotal(std::vector<Shift>{Shift{600, 600}})0

Hint

Sum of (end - start).

Reference solution in C++
int shiftTotal(std::vector<Shift> shifts) {
    int total = 0;
    for (const auto& s : shifts) total += s.end - s.start;
    return total;
}

The same problem in another language

More scheduling problems in C++