回复: 16
跳转到指定楼层
上一主题 下一主题
收起左侧

Google电面

全局:

2016(1-3月) 码农类General 硕士 全职@google - 内推 - 技术电面  | | Other | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
刚刚电面大google,听起来像白人小哥,感觉要跪,做太久,各种写错。
给两个calender schedule, 要设定的meeting time interval, 返回最小的可设置schedule的起始时
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
时长。找出可以约的最早的时间点。如果都没有,比如例子中B的变成[0,5] [20,25] [27,33]就返回33。

上一篇:handshake OA有人收到过吗?
下一篇:Twitter OA 做完没消息

本帖被以下淘专辑推荐:

  • · Google|主题: 54, 订阅: 46
推荐
zdhzh05 2016-4-3 08:51:27 | 只看该作者
全局:
参考leetcode 56 Merge Intervals

思路:
合并schedule A,B(或更多)
sort
merge intervals 返回新的interval list
线性扫描一遍,找到第一个符合meeting长度的gap

Time: O((m+n)log(m+n)) + O(m+n)
Space: O(m+n)

public int getMeetingStartTime(List<Interval> listA, List<Interval> listB, int limit) {
        if (listA == null && listB == null) return 0;
        List<Interval> list = new ArrayList<Interval>();
        if (listA != null) list.addAll(listA);
        if (listB != null) list.addAll(listB);
        if (list.size() == 0) return 0;
        Collections.sort(list, new Comparator<Interval>() {
                @Override
                public int compare(Interval i1, Interval i2) {
                        if (i1.start == i2.start) return i1.end-i2.end;
                        return i1.start-i2.start;
                }
        });
        Interval t = list.get(0);
        List<Interval> res = new ArrayList<Interval>();
        for (int i = 1; i < list.size(); i++) {
                Interval c = list.get(i);
                if (c.start <= t.end) {
                        t = new Interval(t.start, c.end);
                } else {
                        res.add(t);
                        t = c;
                }
        }
        res.add(t);
        for (int i = 1; i < res.size(); i++) {
                if (res.get(i).start-res.get(i-1).end >= limit) {
                        return res.get(i-1).end;
                }
        }
        return res.get(res.size()-1).end;
}

回复

使用道具 举报

推荐
newbiee 2016-4-2 09:54:00 | 只看该作者
全局:
  1. import java.util.*;
  2. import java.io.*;

  3. public class CalenderScheduler {
  4.     //find the first time slot that can schedule the work
  5.     public int find (int[][] schedule1, int[][] schedule2, int required) {
  6.         List<int[]> pos = new ArrayList<int[]>();
  7.         int lastStart = 0;
  8.         for (int[] job : schedule1) {
  9.             pos.add(new int[]{job[0], 1});
  10.             pos.add(new int[]{job[1], -1});
  11.         }
  12.         for (int[] job : schedule2) {
  13.             pos.add(new int[]{job[0], 1});
  14.             pos.add(new int[]{job[1], -1});
  15.         }
  16.         Collections.sort(pos, (a, b) -> {
  17.             return a[0] - b[0];
  18.         });
  19.         //System.out.println(pos.size() + "size #");
  20.         int count = 0;
  21.         int result = 0;
  22.         for (int i = 0; i <= pos.size(); i++) {
  23.             if (i == pos.size()) { // can only allocate after all is done;
  24.                 result = lastStart;
  25.                 break;
  26.             }
  27.             int[] now = pos.get(i);
  28.             if (count == 0) {  // no meeting ongoing
  29.                 if (now[0] - lastStart >= required) { // does the time slot > time required?
  30.                     result = lastStart;
  31.                     break;
  32.                 }
  33.             }
  34.             if (now[1] == 1)
  35.                 count++;
  36.             if (now[1] == -1) {  
  37.                 count--;
  38.                 if (count == 0)
  39.                     lastStart = now[0]; // update the possible start time;
  40.             }
  41.         }
  42.         System.out.println(result);
  43.         return result;

  44.     }

  45.         public static void main(String[] args) {
  46.                 CalenderScheduler test = new CalenderScheduler();
  47.                 int[][] a = {{0,10}, {10, 15}, {13, 20}};
  48.         int[][] b = {{0,5}, {27, 33}};
  49.         int[][] c = {{0,5}, {20, 25}, {27, 33}};
  50.         test.find(a, b, 5);
  51.         test.find(a, c, 5);
  52.         }
  53. }
复制代码

补充内容 (2016-4-2 09:55):
和meeting room 2类似,通过两个测试;
lastStart 记录上一次开始可以约的时间,如果到下一次发生的时间 > required申请时间, 则可以
否则约最后一个结束时间;
回复

使用道具 举报

🔗
say543 2016-4-1 14:46:52 | 只看该作者
全局:
LZ 题不是太懂 能把example 再说说吗?
回复

使用道具 举报

🔗
秦中华 2016-4-1 18:22:30 | 只看该作者
本楼:
全局:
新人回复
回复

使用道具 举报

全局:
楼主这题你当时怎么做的啊,求分享 !!
回复

使用道具 举报

🔗
newbiee 2016-4-2 05:20:35 | 只看该作者
全局:
楼主你的补充说明里面
比如例子中B的变成[0,5] [20,25] [27,33]就返回33。

不是应该返回5吗? 如果只约5分钟的话
回复

使用道具 举报

🔗
 楼主| Violalee119 2016-4-2 05:39:35 | 只看该作者
全局:
newbiee 发表于 2016-4-2 05:20
楼主你的补充说明里面
比如例子中B的变成[0,5] [20,25] [27,33]就返回33。

A不可以呀,要找两个共同的free time slot
回复

使用道具 举报

🔗
 楼主| Violalee119 2016-4-2 06:36:27 | 只看该作者
全局:
有个条件忘记了,每个schedule都是按照开始时间sort过的。
第一个想法是先找到A的可约的所有time slot, 存起来。再跟B的逐一进行比较,然后小哥问我有没有更好的,我说可以两个同时search,search的同时记录当前可以定schedule的时间。贴个code的图,电面的时候写的很混乱,这个是整理过的,估计还是会有问题,欢迎批评指正。


补充内容 (2016-4-2 06:46):
typo,最后一行参数是i,大家领会精神。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
回复

使用道具 举报

🔗
hayreddinluo 2016-4-2 07:45:56 | 只看该作者
全局:
如果A,B两个List不是很长的话,是不是可以先把短的list merge到长的list,然后从这个list里找第一个可选的interval?
回复

使用道具 举报

🔗
Sayings 2016-4-2 10:55:39 | 只看该作者
全局:
newbiee 发表于 2016-4-2 05:20
楼主你的补充说明里面
比如例子中B的变成[0,5] [20,25] [27,33]就返回33。


还有sche A
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表