How to identify the maximum number of overlapping date ranges?

亡梦爱人 提交于 2019-12-02 06:41:58
  • For each range, create two Tuple<DateTime, int>s with values start, +1 and end, -1
  • Sort the collection of tuples by date
  • Iterate through the sorted list, adding the number part of the tuple to a running total, and keeping track of the maximum value reached by the running total
  • Return the maximum value the running total reaches

Executes in O(n log n) because of the sort. There's probably a more efficient way.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!