Drill

ProblemsGo › events

Do two bookings clash

easyeventsIntervalsGo

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

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

Go 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

func bookingsOverlap(firstStart int, firstEnd int, secondStart int, secondEnd int) bool {
	
}

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 Go
func bookingsOverlap(firstStart int, firstEnd int, secondStart int, secondEnd int) bool {
	if firstEnd <= firstStart || secondEnd <= secondStart {
		return false
	}
	return firstStart < secondEnd && secondStart < firstEnd
}

The same problem in another language

More events problems in Go