Drill

ProblemsC# › dates

Do these two bookings clash

easydatesIntervalsC#

A meeting room calendar refuses a booking that runs into another one. Times are minutes since midnight.

IntervalsOverlap(aStart: int, aEnd: int, bStart: int, bEnd: 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

public bool IntervalsOverlap(int aStart, int aEnd, int bStart, int bEnd) {
    
}

Worked examples

CallResult
IntervalsOverlap(60, 120, 110, 180)true
IntervalsOverlap(60, 120, 120, 180)false
IntervalsOverlap(60, 120, 0, 30)false
IntervalsOverlap(60, 120, 70, 80)true

Hint

Two intervals overlap when each one starts before the other ends. Deal with the empty case first.

Reference solution in C#
public bool IntervalsOverlap(int aStart, int aEnd, int bStart, int bEnd) {
    if (aEnd <= aStart || bEnd <= bStart) return false;
    return aStart < bEnd && bStart < aEnd;
}

The same problem in another language

More dates problems in C#