Answer the question
In order to leave comments, you need to log in
How to find intersections among N time intervals?
There are N time periods, of the form
[{
"id": 1,
"start": "2018-08-07 06:00:00+0000",
"end": "2018-08-07 06:15:00+0000"
}, {
"id": 2,
"start": "2018-08-07 06:15:00+0000",
"end": "2018-08-07 06:45:00+0000"
}, {
"id": 3,
"start": "2018-08-07 06:25:00+0000",
"end": "2018-08-07 06:35:00+0000"
}, {
"id": 4,
"start": "2018-08-07 06:10:00+0000",
"end": "2018-08-07 06:30:00+0000"
}]
Answer the question
In order to leave comments, you need to log in
It is necessary to sort events of the form by time {id: 2, type: "start"}
or {id: 4, type: "end"}
Iterate through these times once, moving one at a time, and keeping track of the current window: who is in it. From this it is clear who crossed with whom.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question