Drill

ProblemsC# › events

Do two bookings clash

easyeventsIntervalsC#

A calendar checker takes two half-open intervals and reports whether they overlap.

BookingsOverlap(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

public bool BookingsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
    
}

Worked examples

CallResult
BookingsOverlap(10, 20, 15, 25)true
BookingsOverlap(10, 20, 20, 30)false
BookingsOverlap(10, 20, 25, 30)false
BookingsOverlap(10, 30, 15, 20)true

Hint

Two non-empty intervals overlap when each starts before the other ends.

Reference solution in C#
public bool BookingsOverlap(int firstStart, int firstEnd, int secondStart, int secondEnd) {
    if (firstEnd <= firstStart || secondEnd <= secondStart) return false;
    return firstStart < secondEnd && secondStart < firstEnd;
}

The same problem in another language

More events problems in C#