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

Google 1st round coding challenge

🔗
匿名用户-LMTEF  2026-6-2 01:55:45 来自APP |倒序浏览
💯 1

2026(4-6月) 码农类General 硕士 全职@google - 内推 - 在线笔试  | 😃 Positive 😐 Average | Fail | 在职跳槽

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

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

x
Given an array of on-call rotations
  1. {name, start, end}
复制代码
(half-open intervals
  1. [start, end)
复制代码
), produce the consolidated on-call list for each time segment. Each output segment is a maximal contiguous time range during which the set of people on-call doesn't change. Segments are sorted by
  1. start
复制代码
; gaps with no one on-call are omitted.
on-call list for each
Example
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
     name -= ends[0].name
        ends -= ends[0]

  return result

补充内容 (2026-06-02 15:46 +08:00):
Reference is a pseudocode.
ends is a min heap comparing input.end.
I should put "it = input[i]" at the start of the while loop.

评分

参与人数 4大米 +8 收起 理由
素素是个大学霸 + 1 很有用的信息!
Solumilken + 1 给你点个赞!
匿名用户-HXPAO + 5 感谢分享!
twoRbb + 1 很有用的信息!

查看全部评分


上一篇:tt 两次组面
下一篇:Apple 电面
推荐
邹Albert 2026-6-3 02:36:42 | 只看该作者
全局:

那这种题目扫描线还是比merge interval好  我问这个是觉得如果一开始就排序了 怕他指望要线性时间复杂度的答案
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-GV2FV  2026-6-2 12:41:30
Yeah a typical sweep line problem.


  1. class Status(Enum):
  2.     START = 0
  3.     END = 1

  4. class Solution:

  5.     def consolidate(self, oncalls: list[tuple[int, int, str]]) -> list[tuple[int, int, list[str]]]:
  6.         segments = collections.defaultdict(list)

  7.         for start, end, name in oncalls:
  8.             segments[start].append((name, Status.START))
  9.             segments[end].append((name, Status.END))

  10.         times = sorted(segments)

  11.         names = set()
  12.         consolidated = []
  13.         prev_time = None

  14.         for time in times:
  15.             if prev_time is not None and names:
  16.                 consolidated.append(
  17.                     (prev_time, time, sorted(names))
  18.                 )

  19.             for name, status in segments[time]:
  20.                 if status == Status.START:
  21.                     names.add(name)
  22.                 else:
  23.                     names.remove(name)

  24.             prev_time = time

  25.         return consolidated
复制代码
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-ACEHV  2026-6-2 08:58:55 来自APP
也考到这道题了 不难 但是做的稀烂 估计挂了
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-IZGDL  2026-6-2 04:37:04 来自APP
扫描线解题?
回复

使用道具 举报

🔗
邹Albert 2026-6-2 12:42:05 | 只看该作者
全局:
sort input by start   这里需要手动sort by start  还是一开始就sort好了
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-LMTEF  2026-6-2 15:33:28
邹Albert 发表于 2026-6-1 21:42
sort input by start   这里需要手动sort by start  还是一开始就sort好了

自己sort
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-LMTEF  2026-6-4 02:02:06
邹Albert 发表于 2026-6-2 11:36
那这种题目扫描线还是比merge interval好  我问这个是觉得如果一开始就排序了 怕他指望要线性时间复杂度 ...

好問題。如果已經排序了然後要求線性時間複雜度解,你有想到什麼方式嗎?
回复

使用道具 举报

🔗
邹Albert 2026-6-4 11:11:54 | 只看该作者
全局:
匿名用户 发表于 2026-6-3 14:02
好問題。如果已經排序了然後要求線性時間複雜度解,你有想到什麼方式嗎?

想不到  AI也认为不能
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-NC8LS  2026-6-18 09:01:56
匿名用户 发表于 2026-6-1 17:58
也考到这道题了 不难 但是做的稀烂 估计挂了

结果怎么样了最后
回复

使用道具 举报

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

本版积分规则

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