Problems › TypeScript › scheduling
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
Where you start
function shiftsOverlap(firstStart: number, firstEnd: number, secondStart: number, secondEnd: number): boolean {
}
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 TypeScript
function shiftsOverlap(firstStart: number, firstEnd: number, secondStart: number, secondEnd: number): boolean {
return firstStart < secondEnd && secondStart < firstEnd;
}