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).
- Return
trueif the intervals overlap. - Return
falseif 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
Input
s1=1, e1=5, s2=4, e2=8Output
trueExplanation: Event 2 starts before Event 1 ends.
02EXAMPLE 2
Input
s1=1, e1=3, s2=4, e2=6Output
falseExplanation: Event 1 ends before Event 2 starts.
Constraints
- Inputs are always valid (start < end).
- Return a boolean value.
Control FlowMathLogic
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
s11
e15
s24
e28
Expected Output
true
Click RUN to test your solution