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. hud 6184

    $n$ 点 $m$ 边的图求多少对三元环公用一条边变无向图为有向图 建图方法:对于每条无向边 度数小的端点向度数大的端点连边度数相同则编号小的点向编号大的点连边这样就构成 $DAG$遍历: 遍历每条边 ...

  2. tesonflow实现word2Vec

    word2Vec 是实现从原始语料中学习字词空间向量的预测模型 使用word2Vec的skip_Gram模型 import collections import math import os impo ...

  3. c++ 读取文件字符串 并且解析

    /* "/Users/macname/Desktop/aa-1.log" 链接:https://pan.baidu.com/s/1fKB5vXDe6bYOhoslc-kr7w  密 ...

  4. (转)shell调试方法

    ---恢复内容开始--- 转载:https://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/ Shell脚本调试技术 曹 羽中2007 年 ...

  5. kafka 45个题目介绍

    >1.Kafka面试问答 Apache Kafka的受欢迎程度很高,Kafka拥有充足的就业机会和职业前景.此外,在这个时代拥有kafka知识是一条快速增长的道路.所以,在这篇文章中,我们收集了 ...

  6. javaSE集合---进度2

    一.集合框架 1.特点 对象封装数据,对象多了也需要存储,集合用于存储对象. 对象的个数确定可以使用数组,但是不确定的话,可以用集合,因为集合是可变长度的. 2.集合和数组的区别 数组是固定长度的,集 ...

  7. [Ubuntu] 移植Ubuntu16.04根文件系统到嵌入式平台

    CPU:RK3288 1.通过 ubuntu cdimage 下载 ubuntu16.04 内核,以下两种方式都可以 在 windows 系统网页中下载 http://cdimage.ubuntu.c ...

  8. 近似最近邻算法-annoy解析

    转自https://www.cnblogs.com/futurehau/p/6524396.html Annoy是高维空间求近似最近邻的一个开源库. Annoy构建一棵二叉树,查询时间为O(logn) ...

  9. ArcGIS10.3_解决属性表中文乱码问题

    借鉴前辈们解决ArcMap低版本属性表乱码的问题解决方法,勇敢的尝试了一下Pro中的解决方法,其实道理都一样.先来看看第一种方法:打开CMD,如果是ArcMap,输入如下命令: reg add HKE ...

  10. uboot的仓库在哪里?

    答: https://gitlab.denx.de/u-boot/u-boot# 1. 获取源码 git clone git@gitlab.denx.de:u-boot/u-boot.git Or g ...