Drill

ProblemsJava › events

Do two bookings clash

easyeventsIntervalsJava

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

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

Java 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

boolean 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 Java
boolean 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 Java