Available time
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;
}
随机推荐
- 原生table表格的使用
近期公司让我修改一些之前的table标签写的页面,感觉对table相关的标签不是太熟悉,于是专门整理一下: 1.如果给td标签设置百分比宽度,比如有10列内容,我们却设置了每个单元格是30%的宽度,会 ...
- mac 登陆phpmyadmin 提示 mysqli_real_connect(): (HY000/2002): No such file or directory
我们将下载的phpmyadmin 放在apache目录中,进入phpmyadmin目录, 首先将这个目录中的配置文件改名 sudo mv config.sample.inc.php config.in ...
- java生成临时文件夹和删除临时文件夹
为了不生成同名的文件夹 String s = UUID.randomUUID().toString(); String filepath = ServletActionContext.getServl ...
- java打jar包与找不到依赖包详解
eclipse打jar包与找不到依赖包详解 eclipse打工具jar 1.项目右键-->export -->搜索java 2.选择JAR file 3.打包 eclipse打包可执行ja ...
- 使用IOCP完成端口队列做任务队列
使用IOCP完成端口队列做任务队列 与其自己费力设计异步任务队列,不如使用WINDOWS内核级的IOCP完成端口队列做任务队列. 1)引用单元 uses windows; 2)定义完成端口句柄 var ...
- elasticsearch工作笔记002---Centos7.3安装最新版elasticsearch-7.0.0-beta1-x86_64.rpm单机版安装
新版本es安装问题: https://blog.csdn.net/lidew521/article/details/88091539
- C#实现获取当前文件路径的上级路径
界面: 声明: textBox1.Text为指定文件路径:string path = @"F:\ABB-pragram\ABB工作站\ABB Station\Systems\Situatio ...
- 2019-8-15C#MDI窗体实现多窗口效果
C#MDI窗体实现多窗口效果 Visual C#是微软公司推出的下一代主流程序开发语言,他也是一种功能十分强大的程序设计语言,正在受到越来越多的编程人员的喜欢.在Visual C#中,提供了为实现M ...
- Java设计模式: 单例模式
1.需要传递参数: public class Singleton{ private volatile static Singleton instance = null; private int val ...
- 使用Docker快速搭建Tensorflow开发环境
当我刚开始学习使用scikit-learn时,总是会出现各种各样的包依赖问题,兜兜转转了一遍才全部安装好,现在的机器学习算法开发者大都使用tensorflow.pytorch来实现自己的想法,但依然会 ...