Finding (number of) overlaps in a list of time ranges

后端 未结 9 659
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 19:53

Given a list of time ranges, I need to find the maximum number of overlaps.

Following is a dataset showing a 10 minute interval of calls, from which I am trying to f

9条回答
  •  隐瞒了意图╮
    2020-12-04 20:14

    How about a naive approach:

    • Take the least of the start times and the greatest of the end times (this is your range R)
    • Take the shortest call duration -- d (sorting, O(nlog n))
    • Create an array C, of ceil(R/d) integers, zero initialize
    • Now, for each call, add 1 to the cells that define the call's duration O(n * ceil(R/d))
    • Loop over the array C and save the max (O(n))

    I guess you could model this as a graph too and fiddle around, but beats me at the moment.

提交回复
热议问题