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;
}
随机推荐
- 【原创】go语言学习(十八)反射详解
目录 变量介绍 反射介绍 结构体反射 反射总结以及应用场景 变量介绍 1.变量的内在机制 A. 类型信息,这部分是元信息,是预先定义好的B. 值类型,这部分是程序运行过程中,动态改变的 var arr ...
- xshel链接linuxl安装nginx
原文链接:https://blog.csdn.net/Sweet__dream/article/details/78256952?utm_source=blogxgwz9 这个连接更详细:https: ...
- thymeleaf 直接调用后台Service
前端thymeleaf <select name="sex" class="form-control m-b" th:with="type=${ ...
- legend3---lamp.sh常用操作
legend3---lamp.sh常用操作 一.总结 一句话总结: 1.github上下载代码 2.修改项目数据库配置,修改文件权限等操作:chown -R apache:apache /data/w ...
- Redis 命令使用
Redis 中所有 key-value 都储存在 Redis-Object 中,Redis-Object 主要信息有: 数据类型(type) string (字符串) hash (Hash表) lis ...
- OpenJudge计算概论-忽略大小写比较字符串大小
/*======================================================================= 忽略大小写比较字符串大小 总时间限制: 1000ms ...
- 构建Hadoop监控共同体
HDFS监控背后那些事儿,构建Hadoop监控共同体 原创: 应用研发部 京东云 2018-12-19 https://mp.weixin.qq.com/s/kulwDgwu-rYf4SvQ1dOwc ...
- SQL-W3School-函数:SQL MIX() 函数
ylbtech-SQL-W3School-函数:SQL MIX() 函数 1.返回顶部 1. MIN() 函数 MIN 函数返回一列中的最小值.NULL 值不包括在计算中. SQL MIN() 语法 ...
- python使用redis实现协同控制的分布式锁
python使用redis实现协同控制的分布式锁 上午的时候,有个腾讯的朋友问我,关于用zookeeper分布式锁的设计,他的需求其实很简单,就是节点之间的协同合作. 我以前用redis写过一个网络锁 ...
- Vue.js学习之简介(待续)
Vue.js 渐进式JavaScript 框架 易用:已经会了 HTML.CSS.JavaScript?即刻阅读指南开始构建应用! 灵活:不断繁荣的生态系统,可以在一个库和一套完整框架之间自如伸缩. ...