📣 独立日限时特惠: VIP通行证立减$68
123
返回列表 发新帖
楼主: Lyd.
跳转到指定楼层
上一主题 下一主题
收起左侧

2017/7/13-Facebook电面

🔗
zzgzzm 2017-7-28 12:25:03 | 只看该作者
全局:
jingshihao 发表于 2017-7-28 09:19
发一个我想的跟大家交流下,基本思路就是排序之后一遍pass,如果当前busy interval 的开始是在 desired 的s ...

I think your solution assumes the given time ranges are already sorted and merged.

The interview seems to be interested to do merge and output generation in one pass.
回复

使用道具 举报

🔗
zzgzzm 2017-7-28 12:27:17 | 只看该作者
全局:
Sort and no need to keep an array of merged busy ranges, only need to store the last busy range.
Do merge and outptu generation in one pass:
  1. vector<TimeRange> availableRanges(TimeRange& desired, vector<TimeRange>& busy) {
  2.         busy.emplace_back(desired.end, desired.end); // add dummy end
  3.         sort(busy.begin(), busy.end(), [](TimeRange a, TimeRange b) { return a.start < b.start; });

  4.         vector<TimeRange> available;
  5.         TimeRange lastBusy(desired.start, desired.start); // dummy last busy range

  6.         for (auto& b : busy) {
  7.                 if (lastBusy.end >= desired.end) break;
  8.                 if (b.start > lastBusy.end) {
  9.                         available.emplace_back(lastBusy.end, min(b.start, desired.end));
  10.                         if (b.start < desired.end) lastBusy = b;
  11.                         else break;
  12.                 }
  13.                 else lastBusy.end = max(lastBusy.end, b.end);
  14.         }
  15.         return available;
  16. }
复制代码
回复

使用道具 举报

🔗
zzgzzm 2017-7-28 12:36:34 | 只看该作者
全局:
shuoshuo 发表于 2017-7-26 12:51
是不是可定义一个长度为24的boolean数组,busyt ime置为1, 找到meeting time的区间内为0的字段

The TimeRange class should be very generic with double type "start" and "end", so integer counting technique won't work.
回复

使用道具 举报

🔗
zzgzzm 2017-7-28 12:39:30 | 只看该作者
全局:
bustu 发表于 2017-7-25 10:37
求问楼主,会议没有时长限制 是指什么呢?desired_time.start 和 desired_time.end 代表的是会议开始和结束 ...

The problem actually asks for remaining interval range [desired.start, desired.end] subtracted all busy ranges. The remaining intervals' lengths do not matter, all need to be collected as final result.
回复

使用道具 举报

🔗
bustu 2017-7-29 04:08:16 | 只看该作者
全局:
zzgzzm 发表于 2017-7-28 12:39
The problem actually asks for remaining interval range [desired.start, desired.end] subtracted all ...

Got it! thanks
回复

使用道具 举报

🔗
bustu 2017-7-29 04:08:57 | 只看该作者
全局:
Lyd. 发表于 2017-7-28 06:35
就是会议不需要一定持续多久。start和end只是一个区间,这个区间内任何非busy的时间段都可以排会议。

明白了,谢谢
回复

使用道具 举报

🔗
cgxy1991 2017-7-30 01:00:03 | 只看该作者
全局:
楼主是今年5月毕业的,还是去年毕业的?
回复

使用道具 举报

🔗
vtiaocao 2018-2-22 00:31:33 | 只看该作者
全局:
难道真的是 一题nohire 两题hire……
回复

使用道具 举报

🔗
 楼主| Lyd. 2018-2-22 08:37:35 | 只看该作者
全局:
cgxy1991 发表于 2017-7-30 01:00
楼主是今年5月毕业的,还是去年毕业的?

17年5月毕业的
回复

使用道具 举报

🔗
 楼主| Lyd. 2018-2-22 08:37:59 | 只看该作者
全局:
vtiaocao 发表于 2018-2-22 00:31
难道真的是 一题nohire 两题hire……

哈哈有这个说法吗?那我感到安慰了许多
回复

使用道具 举报

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

本版积分规则

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