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基础系列 - equals和==的区别

    package com.test7; public class test7 { public static void main(String[] args) { /** * 1.equals()比较的 ...

  2. TTFB 时间过长

    记录一个问题吧. 新上线的应用,第一次上线部署了两个节点,通过DMZ的NGINX映射出去的. 上线之后,第三天突然发现访问很慢,有50%的几率保持在7秒左右,通过日志平台观察代码处理时间在40ms左右 ...

  3. python中的with的用法,上下文管理器

    with是从Python2.5引入的一个新的语法,它是一种上下文管理协议,目的在于从流程图中把 try,except 和finally 关键字和 资源分配释放相关代码统统去掉,简化try….excep ...

  4. Linux中touch命令使用(创建文件)

    touch命令有两个功能: 1.用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来: 2.用来创建新的空文件. 语法 touch(选项)(参数) 选项 -a:或 ...

  5. 关于form与表单提交操作的一切

    原文链接:http://caibaojian.com/form.html 你知道,一个表单里面只要有form元素,如果没有给action加一个默认值,为空白的时候,当你刷新页面时,会弹出一个警告框提示 ...

  6. C# [ThreadStatic] 标记静态字段对多线程执行的影响

    类的静态字段在类的实例中是共享的.多个线程修改实例字段的值在对其它线程来说是可见的,这也是clr默认的行为.对静态字段添加ThreadStaticAttribute标记可以改变这种默认的行为. Thr ...

  7. angular 中如何使用自定义组件

    1.创建header组件 ng g component components/header header.component.ts import { Component, OnInit } from ...

  8. python小白之np功能快速查

    np一些用法 np.a np.array([1,2,3],dtype=int)  #建立一个一维数组, np.array([[1,2,3],[2,3,4]])  #建立一个二维数组. np.arang ...

  9. 目标检测中的选择性搜索-selective search-没弄

    https://blog.csdn.net/small_munich/article/details/79595257 https://www.cnblogs.com/zyly/p/9259392.h ...

  10. OpenStack Heat模板内部函数

    Heat模板内部函数又称为Intrinsic functions. 注:Intrinsic functions只能用在 resource 的 properties 段 和 outputs 中.    ...