📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 6
跳转到指定楼层
上一主题 下一主题
收起左侧

google 面经题

全局:

2016(1-3月) 码农类General 硕士 全职@google - 内推 - HR筛选  | | Other | 其他

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

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

x
Considering there are N engineers in one company with id from 1 to N, Each of the Engineer has a skill rate R_i, we want to select one group of engineering whose ids have to be continuous. The size of o
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
all the groups whose size is X.”是说每个window中找最小值,然后求的是整个过程中的最大值. 如果用hash heap的话可以到O(nlgnk), 如果是普通的话是O(nk)

上一篇:facebook电面
下一篇:Dropbox电面
🔗
 楼主| bobzhang2004 2016-4-1 10:38:33 | 只看该作者
全局:
写了下第一轮的代码,这里使用普通的priorityqueue, 时间复杂度是O(nk)
  1. public class MaximumInMinimumInWindowK {

  2.         public static void main(String[] args) {
  3.                 int[] arr = {3, 2, 5, 2, 9, 3, 7, 6, 5};
  4.                 System.out.println(getMaximumInMinimumInWindowK(arr, 3));
  5.         }
  6.         public static int getMaximumInMinimumInWindowK(int[] arr, int k) {
  7.                 if (arr == null || arr.length == 0) {
  8.                         return Integer.MIN_VALUE;
  9.                 }
  10.                 int res = Integer.MIN_VALUE;
  11.                 PriorityQueue<Integer> pq = new PriorityQueue<Integer>(k);
  12.                 for (int i = 0; i < arr.length; i++) {
  13.                         pq.offer(arr[i]);
  14.                         if (i >= k - 1) {
  15.                                 res = Math.max(res, pq.peek());
  16.                                 pq.remove(arr[i - k + 1]);
  17.                         }
  18.                 }

  19.                 return res;
  20.         }
  21. }
复制代码
回复

使用道具 举报

🔗
say543 2016-4-1 14:42:01 | 只看该作者
全局:

谢分享 感觉像是sliding window 找出所有window 的representatives(每个window 以最小为representatives) 然后取最大的 因该o(nk) 就行了? dequeue 感觉就足够?
回复

使用道具 举报

🔗
ok123 2016-4-3 11:30:47 | 只看该作者
全局:
》》java普通的priorityqueue删除是O(n)的啊
题目没有看懂。但是 priorityQ remove应该是lgN吧

用最后一个元素overwrite要remove的,让后heapify这个node
回复

使用道具 举报

🔗
Alice0701 2016-4-4 03:51:56 | 只看该作者
全局:
赞楼主 谢谢分享!
回复

使用道具 举报

🔗
jy_121 2016-4-27 00:30:03 | 只看该作者
全局:
ok123 发表于 2016-4-3 11:30
》》java普通的priorityqueue删除是O(n)的啊
题目没有看懂。但是 priorityQ remove应该是lgN吧

查找要删除的元素不是要O(n)吗?
回复

使用道具 举报

🔗
Peripatetic 2016-4-27 03:36:38 | 只看该作者
全局:
Maximun sliding window变种 找每个window最小值 最后取所有最小的最大 线性时间
回复

使用道具 举报

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

本版积分规则

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