Do these two shifts overlap
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.
- A shift ends exactly when the next begins: that is still a handover, not an overlap.
- Shifts never wrap past midnight here.
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.
Where you start
public bool ShiftsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
}
Worked examples
| Call | Result |
|---|---|
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#
public bool ShiftsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
return firstStart < secondEnd && secondStart < firstEnd;
}