gpt4 book ai didi

javascript - 日历问题和识别空闲槽

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:37:42 25 4
gpt4 key购买 nike

我正在尝试解决间隔日历问题。

Given busy slots as a data-set in a person's outlook  calendar andthe time required for a meeting (eg: 45 mins) write a method to findan open available slot for scheduling a meeting.

Input:
per1: (1,5) (10, 14) (19,20) (27,30)

per2: (3,5) (12,15) (18,21) (23,24)
Output: (6,9) (16,17) (22,22) (25,26)

我正在尝试查看如何使用以下方法解决此问题:

A) 原生 JavaScript (ES5/ES6)

B) 使用区间树等数据结构

我在想也许可以结合两个日历并按开始时间的升序对它们进行排序,然后开始寻找空位?如果我错了,请纠正我。

同样需要您的意见/建议。

最佳答案

鉴于它是一个绝对时间的元组并且只涉及两个人,您可以维护一个长度为 24 的状态数组。运行一个循环来标记 p1 和 p2 忙碌的所有时间。您将留下他们两个都不忙的一系列时间,然后提取这些时间间隔之间的绝对差距。这是一个处理繁忙时间标记的 fiddle ( https://jsfiddle.net/r9nq63tk/1/)。

let freeHours = new Array(24);
// Mark the busy hours
let intervals = [];
for(let hours = 0; hours < 24; hours++) {
// Find the ranges where the hours have not been marked and push it to intervals
}

关于javascript - 日历问题和识别空闲槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55234906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com