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

后端 未结 9 626
爱一瞬间的悲伤
爱一瞬间的悲伤 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:32

    Following must work:

    1. Sort all your time values and save Start or End state for each time value.
    2. Set numberOfCalls to 0 (count variable)
    3. Run through your time values and:

      • increment numberOfCalls if time value marked as Start
      • decrement numberOfCalls if time value marked as End
      • keep track of maximum value of numberOfCalls during the process (and time values when it occurs)

    Complexity: O(n log(n)) for sorting, O(n) to run through all records

提交回复
热议问题