The Overlap Detector

MediumAcc. 86.5%
+30 XP 12

Collision in Time

Interval overlap is a classic computer science problem. You are given two events, each with a start and an end time. Your goal is to determine if these events share any common time (even a single moment).

The Assignment

Your function receives four numbers: s1, e1 (Event 1) and s2, e2 (Event 2).

  1. Return true if the intervals overlap.
  2. Return false if they are separate.

Tip: Two intervals do not overlap if one ends before the other begins (e1 <= s2) or vice versa (e2 <= s1). The overlap is the inverse of this logic!

01EXAMPLE 1

Inputs1=1, e1=5, s2=4, e2=8
Outputtrue

Explanation: Event 2 starts before Event 1 ends.

02EXAMPLE 2

Inputs1=1, e1=3, s2=4, e2=6
Outputfalse

Explanation: Event 1 ends before Event 2 starts.

Constraints

  • Inputs are always valid (start < end).
  • Return a boolean value.
Control FlowMathLogic
JavaScript
Loading...
4 Hidden

Input Arguments

s11
e15
s24
e28

Expected Output

true

Click RUN to test your solution