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

google 电面+onsite

全局:

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

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

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

x
google是17年10月和hr沟通的,拖到了18年1月面试,lc google题目刷了2遍,不熟的又看了1遍

电面:
lc google tag原题,感觉像国人,就不上题目了。

onsite:
round 1: lc463,就一道题,不过矩阵边界处视为0,dfs秒了。
round 2: 好奇怪,胡乱问问题,交流有障碍。什么是ip地址,举个例子,如何把一个整数解析成i
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
trong>补充内容 (2018-3-29 01:39):
加面两轮onsite

补充内容 (2018-5-10 08:05):
拿到了offer,去了fb

评分

参与人数 3大米 +45 收起 理由
financeFree + 10 很有用的信息!
mtfront + 5 给你点个赞!
hurricane_e + 30

查看全部评分


上一篇:fb 电面+onsite
下一篇:报个U家Offer和面经 附G家跪经
推荐
jasonyang04 2018-3-10 16:01:12 | 只看该作者
全局:
请问楼主是new grad吗?另外我觉得第五题好像就是LC543的变种,你看是不是?
回复

使用道具 举报

全局:
第五题好好写了一下,想问下会有val一样的treenode么?是保证肯定只有一个根节点么?
楼主觉得这样可以么:

  1. import java.util.*;

  2. public class Solution{
  3.         static class TreeNode{
  4.                 List<TreeNode> children;
  5.                 int val;
  6.                 public TreeNode(int val){
  7.                         this.val = val;
  8.                         this.children = new ArrayList<>();
  9.                 }
  10.         }
  11.        
  12.         public static void main(String[] args) {
  13.                 int[][] edges = {{0, 1}, {0, 2}, {0, 3}, {1, 4}, {1,6}, {4,5}, {6,7}, {5,8}, {7,9}, {6,10}};
  14.                 System.out.println(maxLength(edges));
  15.         }
  16.        
  17.         public static int maxLength(int[][] edges){
  18.                 Map<Integer, TreeNode> map = new HashMap<>();
  19.                 Map<Integer, Integer> indegree = new HashMap<>();
  20.                 for(int[] edge : edges){
  21.                         int n1 = edge[0];
  22.                         int n2 = edge[1];
  23.                         if(!map.containsKey(n1)){
  24.                                 map.put(n1, new TreeNode(n1));
  25.                         }
  26.                         if(!map.containsKey(n2)){
  27.                                 map.put(n2, new TreeNode(n2));
  28.                         }
  29.                         if(!indegree.containsKey(n1)){
  30.                                 indegree.put(n1, 0);
  31.                         }
  32.                         if(!indegree.containsKey(n2)){
  33.                                 indegree.put(n2, 0);
  34.                         }
  35.                         map.get(n1).children.add(map.get(n2));
  36.                         indegree.put(n2, indegree.getOrDefault(n2, 0) + 1);
  37.                 }
  38.                 TreeNode root = null;
  39.                 for(Map.Entry<Integer, Integer> entry : indegree.entrySet()){
  40.                         if(entry.getValue() == 0){
  41.                                 root = map.get(entry.getKey());
  42.                                 break;
  43.                         }
  44.                 }
  45.                 int[] max = {0};
  46.                 height(root, max);
  47.                 return max[0];
  48.         }
  49.        
  50.         private static int height(TreeNode root, int[] max){
  51.                 if(root.children.size() == 0){
  52.                         return 1;
  53.                 }
  54.                 int max1 = -1;
  55.                 int max2 = -1;
  56.                 for(TreeNode child : root.children){
  57.                         int h = height(child, max);
  58.                         if(max1 == -1){
  59.                                 max1 = h;
  60.                         }else{
  61.                                 if(h >= max1){
  62.                                         max2 = max1;
  63.                                         max1 = h;
  64.                                 }else if(h > max2){
  65.                                         max2 = h;
  66.                                 }
  67.                         }
  68.                 }
  69.                 if(max1 != -1 && max2 != -1){
  70.                         max[0] = Math.max(max[0], max1 + max2 + 1);
  71.                 }
  72.                 return max1 + 1;
  73.         }
  74. }
复制代码
回复

使用道具 举报

推荐
619899442 2018-3-10 14:30:40 | 只看该作者
全局:
My DP solution for Q5
  1. class Solver {
  2.     private int rt;
  3.     private int[] maxSubDist;
  4.     // graph
  5.     private Map<Integer, Set<Integer>> graph;
  6.     private int[] bottom;

  7.     // O(n) because of memo
  8.     private int maxDistToBottom(int root, int father) {
  9.         if (bottom[root] != -1) {
  10.             return bottom[root];
  11.         }
  12.         int res = 0;
  13.         for (int child : graph.get(root)) {
  14.             if (child == father) {
  15.                 continue;
  16.             }
  17.             res = Math.max(res, 1 + maxDistToBottom(child, root));
  18.         }
  19.         bottom[root] = res;
  20.         return res;
  21.     }

  22.     // O(n) because of memo
  23.     private int maxDist(int root, int father) {
  24.         if (maxSubDist[root] != -1) {
  25.             return maxSubDist[root];
  26.         }

  27.         int max1 = -1; // largest
  28.         int max2 = -1; // second largest
  29.         List<Integer> children = new ArrayList<>();
  30.         for (int child : graph.get(root)) {
  31.             if (child == father) {
  32.                 continue;
  33.             }
  34.             children.add(child);
  35.             if (bottom[child] >= max1) {
  36.                 max2 = max1;
  37.                 max1 = bottom[child];
  38.             } else if (bottom[child] > max2) {
  39.                 max2 = bottom[child];
  40.             }
  41.         }
  42.         if (children.size() == 0) {
  43.             // leaf node
  44.             maxSubDist[root] = 0;
  45.             return 0;
  46.         } else if (children.size() == 1) {
  47.             maxSubDist[root] = maxDist(children.get(0), root);
  48.             return maxSubDist[root];
  49.         } else {
  50.             // children >= 2
  51.             int res = 0;
  52.             for (int child : children) {
  53.                 res = Math.max(res, maxDist(child, root));
  54.             }
  55.             maxSubDist[root] = Math.max(res, 2 + max1 + max2);
  56.             return maxSubDist[root];
  57.         }
  58.     }


  59.     public Solver(int[][] edges) {
  60.         int n = edges.length + 1;
  61.         graph = new HashMap<>();
  62.         for (int i = 0; i < edges.length; ++i) {
  63.             graph.putIfAbsent(edges[i][0], new HashSet<>());
  64.             graph.putIfAbsent(edges[i][1], new HashSet<>());

  65.             graph.get(edges[i][0]).add(edges[i][1]);
  66.             graph.get(edges[i][1]).add(edges[i][0]);
  67.         }

  68.         maxSubDist = new int[n];
  69.         Arrays.fill(maxSubDist, -1);
  70.         bottom = new int[n];
  71.         Arrays.fill(bottom, -1);
  72.         rt = 0;
  73.         for (int i = 0; i < n; ++i) {
  74.             if (graph.get(i).size() > graph.get(rt).size()) {
  75.                 rt = i;
  76.             }
  77.         }
  78.     }

  79.     public int solve() {
  80.         maxDistToBottom(rt, rt);
  81.         return maxDist(rt, rt);
  82.     }
  83. }
复制代码

补充内容 (2018-3-10 14:32):
这个解法assumed图至少有3个节点,对于图只包含1/2个节点可以当作特殊情况处理
回复

使用道具 举报

🔗
zhouz88 2018-3-10 12:10:53 | 只看该作者
全局:
楼主求个 谷歌 面经!
回复

使用道具 举报

🔗
 楼主| zhanglixue 2018-3-10 14:46:19 | 只看该作者
全局:

我的解法比较简单,删除叶子结点,如果叶子结点数目大于等于2,则总长度加2,否则总长度加1,不停的删叶子结点,直到删光整幅图。
面试官说这个算法他没见过。。。。
回复

使用道具 举报

🔗
 楼主| zhanglixue 2018-3-10 14:47:34 | 只看该作者
全局:
zhouz88 发表于 2018-3-10 12:10
楼主求个 谷歌 面经!

面经在这里啊。。。。
回复

使用道具 举报

🔗
619899442 2018-3-10 15:08:24 | 只看该作者
全局:
zhanglixue 发表于 2018-3-10 14:46
我的解法比较简单,删除叶子结点,如果叶子结点数目大于等于2,则总长度加2,否则总长度加1,不停的删叶 ...

有意思,请问lz是怎么想到的这种解法呢?
回复

使用道具 举报

🔗
619899442 2018-3-10 15:29:26 | 只看该作者
全局:
还有请问楼主第三轮的具体要求是什么呢?
回复

使用道具 举报

🔗
dawskiper 2018-3-10 15:46:37 | 只看该作者
全局:
请教LZ,“抽取出里面的email”是什么意思?文件里面存的不是IP地址吗?

补充内容 (2018-3-10 15:48):
Emmm刚看到更新,是匹配文档里面的的email吗?比如设计一个正则。
回复

使用道具 举报

🔗
 楼主| zhanglixue 2018-3-10 15:51:38 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

🔗
 楼主| zhanglixue 2018-3-10 15:53:45 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

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

本版积分规则

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