jasonbogd jasonbogd - 1 year ago 112
C Question

Determine if ranges overlap

Given two events with integer start and end times, E1 = (s1, e1), E2 = (s2, e2), implement a quick boolean check to see if the events overlap.

I have the solution, but I'm curious to see what others come up with.

EDIT: OK, here's my solution:

e1 > s2 || (s1 > s2 && e2 < s1)

Answer Source

bool overlap = (s1 <= e2) && (s2 <= e1)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download