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

发个Google Onsite

🔗
匿名用户-0NYI6  2016-3-9 07:14:10 |倒序浏览

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

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

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

x
第一轮,tree版的 clone graph,状态不太好,被提醒了几次,有些无用的变量和步骤, 然后问了一下进程间通信怎么实现, 我答了通过文件或者socket

第二轮,就一道题   完完全全不会做, 面了这轮就知道悲剧了。。。
给一个un sorted array  长度为n
可以用
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
n * k ^ -2,  对应最小值的k 就是 sqrt(2n) / 4  

补充内容 (2016-3-9 10:47):
将k 值带入 时间复杂度和空间复杂度都能得到 O(logn)

评分

参与人数 6大米 +91 收起 理由
mrhohn + 3 感谢分享!
zjuzqh + 3 感谢分享!
Fustang + 2 回答的很好!
爱丽丝和鲍勃 + 20
Ulu2005 + 3 感谢分享!

查看全部评分


上一篇:bloomberg电面面经,秒给onsite
下一篇:3月4号电面F家水过~
推荐
ryancooper 2016-3-10 00:28:52 | 只看该作者
全局:
论坛匿名用户 发表于 2016-3-9 11:11
三哥提醒出来的。。。。

准确来说你这个解法还不是时间和空间都是logn的做法啊,而是sqrt(n)吧。这里的思想是macro/micro decomposition。
回复

使用道具 举报

推荐
csgtc 2016-3-9 07:37:33 | 只看该作者
全局:
第二题不就是裸的线段树么。。挺容易的呀 segment tree
回复

使用道具 举报

推荐
guschen802 2016-3-9 09:01:19 | 只看该作者
全局:
根據2樓提示,現學了一把segment tree, 求大神們檢查和指教,謝謝!

  1. public class UnsortedArray {
  2.     public static void main(String[] args) {
  3.         UnsortedArray us = new UnsortedArray(new int[]{5,4,2,1,9,8,7});
  4.         System.out.println(us.getIntervalMax(2,3) == 2);
  5.         System.out.println(us.getIntervalMax(0,5) == 9);
  6.         System.out.println(us.getIntervalMax(4,6) == 9);
  7.         System.out.println(us.getIntervalMax(5,6) == 8);
  8.         System.out.println(us.getIntervalMax(3,3) == 1);
  9.     }
  10.     private int[] array;
  11.     private SegmentNode root;
  12.     public UnsortedArray(int[] array) {
  13.         this.array = array;

  14.         if (array == null && array.length == 0) {
  15.             throw new IllegalArgumentException();
  16.         }

  17.         Queue<SegmentNode> queue = new LinkedList<>();

  18.         for (int i = 0; i < array.length; i++) {
  19.             queue.offer(new SegmentNode(i,i,array[i]));
  20.         }

  21.         while (queue.size() >1) {
  22.             int size = queue.size();
  23.             for (int i = 0; i < size;) {
  24.                 if (i == size-1) {
  25.                     queue.offer(queue.poll());
  26.                     break;
  27.                 }
  28.                 SegmentNode left = queue.poll();
  29.                 SegmentNode right = queue.poll();

  30.                 SegmentNode newNode = new SegmentNode(left.start, right.end, Math.max(left.max, right.max));
  31.                 newNode.left = left;
  32.                 newNode.right = right;
  33.                 queue.offer(newNode);
  34.                 i += 2;
  35.             }
  36.         }
  37.         root = queue.poll();
  38.     }

  39.     public int getIntervalMax (int i, int j) {
  40.         if (i < 0 || j < 0 || i >= array.length || j>= array.length ||i >j) {
  41.             throw new IllegalArgumentException();
  42.         }

  43.         return helper(root,i,j);
  44.     }

  45.     private int helper(SegmentNode node,int i, int j) {
  46.         if (node.start == i && node.end == j) {
  47.             return node.max;
  48.         }
  49.         if (i > node.mid) {
  50.             return helper(node.right, i, j);
  51.         }
  52.         if (j <= node.mid) {
  53.             return helper(node.left, i, j);
  54.         }

  55.         return Math.max(helper(node.left, i, node.mid), helper(node.right, node.mid+1, j));

  56.     }

  57.     class SegmentNode {
  58.         int start;
  59.         int end;
  60.         int mid;
  61.         int max;
  62.         SegmentNode left;
  63.         SegmentNode right;

  64.         public SegmentNode(int start, int end, int max) {
  65.             this.start = start;
  66.             this.end = end;
  67.             mid = start + (end - start)/2;
  68.             this.max = max;
  69.         }

  70.         @Override
  71.         //for debug
  72.         public String toString() {
  73.             return "SegmentNode{" +
  74.                     "start=" + start +
  75.                     ", end=" + end +
  76.                     ", max=" + max +
  77.                     '}';
  78.         }
  79.     }
  80. }
复制代码
回复

使用道具 举报

🔗
guschen802 2016-3-9 07:42:03 | 只看该作者
全局:
第二題我也不太懂唉,自己想了一個。。不知道算不算log(n);

  1. public class UnsortedArray {
  2.     public static void main(String[] args) {
  3.         UnsortedArray us = new UnsortedArray(new int[]{1,1,1,1,1,6,1,1,1,1});
  4.         System.out.println(us.getIntervalMax(2,3));
  5.         System.out.println(us.getIntervalMax(0,5));
  6.         System.out.println(us.getIntervalMax(4,6));
  7.         System.out.println(us.getIntervalMax(5,6));

  8.     }
  9.     private int[] array;
  10.     private int[] maxArray;
  11.     public UnsortedArray(int[] array) {
  12.         this.array = array;

  13.         if (array == null && array.length == 0) {
  14.             throw new IllegalArgumentException();
  15.         }

  16.         //maxArray[i] == max value from 0 ~ i
  17.         maxArray = new int[array.length];
  18.         maxArray[0] = array[0];
  19.         for (int i = 1; i < array.length; i++) {
  20.             maxArray[i] = Math.max(maxArray[i-1], array[i]);
  21.         }
  22.     }

  23.     public int getIntervalMax (int i, int j) {
  24.         if (i < 0 || j < 0 || i >= array.length || j>= array.length ||i >j) {
  25.             throw new IllegalArgumentException();
  26.         }

  27.         //if maxArray[j]'s value is not equal to maxArray[i-1], which means maxArray[j]'s value
  28.         // must come from i~j, then just return
  29.         //O(1)
  30.         if (i == 0 || maxArray[j] != maxArray[i-1]) {
  31.             return maxArray[j];
  32.         }

  33.         //find max during i~j
  34.         //O(j-i)
  35.         int max = array[i];
  36.         for (int x = i +1; x <= j; x++) {
  37.             max = Math.max(array[x], max);
  38.         }
  39.         return max;
  40.     }
  41. }
复制代码

补充内容 (2016-3-9 07:42):
無視test case...後來隨手改了一個= =

补充内容 (2016-3-9 09:01):
樓下發了個segment tree版的,現學的。。
回复

使用道具 举报

🔗
guschen802 2016-3-9 07:44:06 | 只看该作者
全局:
csgtc 发表于 2016-3-9 07:37
第二题不就是裸的线段树么。。挺容易的呀 segment tree

最近才聽說的segment tree呢。。表示自己好無知啊。。求問還有什麼類似的高級一點的數據結構?想去了解下
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-0NYI6  2016-3-9 09:20:02
csgtc 发表于 2016-3-9 07:37
第二题不就是裸的线段树么。。挺容易的呀 segment tree

我给他说了一下线段树了。不过我当时说的空间o(n),   他说得log n      我发错了。pre computation 是要小于o n 空间
回复

使用道具 举报

🔗
guschen802 2016-3-9 09:31:29 | 只看该作者
全局:
论坛匿名用户 发表于 2016-3-9 09:20
我给他说了一下线段树了。不过我当时说的空间o(n),   他说得log n      我发错了。pre computation 是要 ...

唉。。要log(n)的話。。。-0-投降,求來個大神指教
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-0NYI6  2016-3-9 10:48:49
guschen802 发表于 2016-3-9 09:31
唉。。要log(n)的話。。。-0-投降,求來個大神指教

我把当时的做法更新上去了
回复

使用道具 举报

🔗
william_gong 2016-3-9 11:11:43 | 只看该作者
全局:
第二轮能想出这个做法也是够厉害的。。。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-0NYI6  2016-3-9 11:11:59
william_gong 发表于 2016-3-9 11:11
第二轮能想出这个做法也是够厉害的。。。

三哥提醒出来的。。。。
回复

使用道具 举报

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

本版积分规则

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