Given a log file which records the start and end timestamp of each task processed by a server, in the format:
<Start time> <End time>
What is the maximum number of concurrent running tasks?
Example:
09:00:00 - 06/01/2022 10:40:10 - 06/01/2022
09:20:00 - 06/01/2022 09:40:10 - 06/01/2022
08:00:00 - 06/01/2022 11:40:10 - 06/01/2022
Question: What is the maximum number of concurrent running tasks?
这道题本质上是经典的区间重叠问题:每个任务有开始时间和结束时间,要求计算任意时刻最多有多少个任务同时运行。通常做法是把所有开始和结束事件拆开,按时间排序后用扫描线统计当前活跃任务数,并维护全局最大值。若题目要求精确到同一时刻的先后顺序,需要明确结束时间是否算作占用区间边界,但在常见面试实现里通常可以通过事件排序规则统一处理。
正文完