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. Java监听器listener的介绍

    Java监听器listener的介绍 listener 能做什么 当web中某些动作发生之后,服务器就调用listener中对应的方法. 内部机制 接口回调 Web监听器 步骤 创建需要的监听器类,实 ...

  2. kaptcha 配置

    问题所在: 这一段配置,不要写在 SpringMVC 文件中,要写在 Spring 配置文件! <!-- kaptcha 验证码 --> <bean id="captcha ...

  3. lucene正向索引(续)——域(Field)的元数据信息在.fnm里,在倒排表里,利用跳跃表,有利于大大提高搜索速度。

    4.1.2. 域(Field)的元数据信息(.fnm) 一个段(Segment)包含多个域,每个域都有一些元数据信息,保存在.fnm文件中,.fnm文件的格式如下: FNMVersion 是fnm文件 ...

  4. LeetCode 第 153 场周赛

    一.公交站间的距离(LeetCode-5181) 1.1 题目描述 1.2 解题思路 比较简单的一题,顺时针.逆时针两次遍历,就能解决. 1.3 解题代码 class Solution { publi ...

  5. Java打印素数(质数)

    要求:打印 2 - 100000 当中的素数与非素数.(素数定义:在大于1的自然数中,除了1和它本身以外不再有其他因数) 1. 常规方式——对正整数n,如果用2到  之间的所有整数去除,均无法整除,则 ...

  6. 如果前面的IO操作出问题了,按照我们代码的意思,不就try catch 了吗,这样的话线程就没关闭了,就会造成线程泄露。 那怎么解决这个问题呢,其实也简单,把关闭线程的方法写到finally里就可以了。

    https://mp.weixin.qq.com/s/WaNVT2bZFGHNO_mb5nK6vw 连HDFS源码大神都会犯的错之线程泄露(1) 西瓜老师 西瓜老师爱大数据 1月11日  

  7. Web前端接入人机识别验证码---腾讯防水墙

    Web前端接入 1. 准备AppID 验证码接入需要先在管理后台中注册获取APPID和APPSECRET,注册步骤请参考 快速开始 2. 快速接入步骤 1.在Head的标签内最后加入以下代码引入验证J ...

  8. Facebook libra开发者文档- 1 -welcome

    参考https://developers.libra.org/docs/welcome-to-libra 欢迎来到Libra开发者网站!Libra的使命是建立一个简单的全球货币和金融基础设施,为数十亿 ...

  9. Java 8 Lambda表达式学习和理解

    Java 8 Lambda表达式和理解 说明:部分资料来源于网络 时间:20190704 Lambda 表达式,也可称为闭包,它是推动 Java 8 发布的最重要新特性.Lambda 允许把函数作为一 ...

  10. QML登录界面

    import QtQuick 2.9 import QtQuick.Window 2.2 import QtQuick.Controls 2.2 import QtGraphicalEffects 1 ...