Google Calendar, Outlook, iCal has been banned from your company! So an intrepid engineer has decided to roll their own implementation. Unfortunately one major missing feature is the ability to find out what time slots are free for a particular individual.

Given a list of time blocks where a particular person is already booked/busy, a start and end time to search between, a minimum duration to search for, find all the blocks of time that a person is free for a potential meeting that will last the aforementioned duration.

Given: start_time, end_time, duration, meetings_list -> suggested_meeting_times

Let's assume we abstract the representation of times as simple integers, so a valid time is any valid integer supported by your environment. Here is an example input:

meetings_list: [3,20], [-2, 0], [0,2], [16,17], [19,23], [30,40], [27, 33]

start_time: -5

end_time: 27

min_duration: 2

expected answer:

free_time: [-5, -2], [23,27]

Feel free to represent the meetings however you would like, i.e. List of Lists, Lists of Objects etc.

 public static List<List<Integer>> scheduler(List<List<Integer>> meetings, int start, int end, int duration) {
List<List<Integer>> ans = new ArrayList<>();
if (duration == ) return ans;
Collections.sort(meetings, (a, b) -> a.get() - b.get());
for (List<Integer> meeting : meetings) {
int curEnd = Math.min(meeting.get(), end);
if (curEnd - start >= duration) {
ans.add(Arrays.asList(start, curEnd));
}
start = Math.max(start, meeting.get());
if (start >= end)
break;
}
if (end - start >= duration)
ans.add(Arrays.asList(start, end));
return ans;
}

随机推荐

  1. luogu 2617

    动态区间 $k$ 大主席树 + 树状数组树状数组的每个点对应一颗线段树首先将所有点加入数据结构 枚举 x code: for(int i = x; i <= n; i += Lowbit(i)) ...

  2. 51nod 1459 & 1212

    1459 双限制最短路 #include <stdio.h> #include <iostream> #include <vector> #include < ...

  3. 18.4.09 模拟考 zhx P75

    题目链接 https://files.cnblogs.com/files/lovewhy/P75.pdf P75 竞赛时间: ????年??月??日??:??-??:?? 注意事项(请务必仔细阅读) ...

  4. linux中清理旧内核

    执行update的时候会自动升级内核,开机启动的时候会好多内核选项.所以我们要清理不需要内核. 查看当前系统使用的内核版本 uname -a Linux localhost.localdomain 3 ...

  5. filter方法求出列表所有奇数并构造新列

    a = [, , , , , , , , , ] b = filter(lambda x: x % != , a) for i in b: print(i)

  6. hadoop2.9.2 调整jvm

    错误:namenode挂掉 查看hadoop的日志文件,发现存在大量的GC,导致namenode挂掉 命令行执行错误信息: 解决: 查看系统内存: # /data1/hadoop/hadoop/etc ...

  7. python3编程基础之一:代码封装

    几乎现代的编程语言都支持函数,函数是代码段的封装,并能实现一特定功能,并能重复使用的代码单位.之前的pow()和sqrt()和print()和input()等类似的内置函数,就是python内部已经实 ...

  8. js小脚本解析后台数据

    java代码 List<CodeTableBean> clfsList = StandardCodeTable.getCodeTable("clfs", "& ...

  9. win7下如何根据端口号杀掉进程

    点击windows左下窗口图标按钮.   输入cmd   输入netstat -ano后回车.   左边箭头指向端口号,右边箭头指向为这个端口号对应的进程号pid,我们记下pid号   我们以2001 ...

  10. 迭代器Iterator、for循环遍历、泛型

    java.util.Collection接口 是集合的最顶层的接口,定义了集合共性的方法 接口无法直接创建对象,使用多态的方式创建对象 Collection<集合中的数据类型(泛型)> c ...