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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)