Drill

ProblemsC++ › scheduling

Do these two shifts overlap

easyschedulingIntervalsC++

Time-and-a-half rules ban one person covering two shifts at once. Minutes are counted from midnight; decide whether two shift windows share any time at all.

shiftsOverlap(firstStart: int, firstEnd: int, secondStart: int, secondEnd: int) → bool

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

bool shiftsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
    
}

Worked examples

CallResult
shiftsOverlap(480, 900, 840, 1020)true
shiftsOverlap(480, 900, 900, 1020)false
shiftsOverlap(480, 840, 900, 1020)false
shiftsOverlap(480, 900, 500, 600)true

Hint

Two windows overlap exactly when each starts before the other ends.

Reference solution in C++
bool shiftsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
    return firstStart < secondEnd && secondStart < firstEnd;
}

The same problem in another language

More scheduling problems in C++