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

Google 12/01 onsite面经

全局:

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

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

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

x
土木硕士转专业,Google是第一家给onsite的。面试在kirkland,整体过程不算非常困难,总感觉google的面试(甚至所有IT公司的面试)都有从题目易懂但算法难想向题目综合,问题复杂但算法知识要求降低的变化趋势。传说中Google最爱的DP完全没有遇到,倒是图,树,DFS,BFS这些比较容易结合具体问题的知识点考了很多。发面经求好运。
时间线
•          15th Oct – 内推
•          17th Oct – 收到OA
•          23rd Oct – 完成OA
•          31st Oct – 收到HR邮件OA通过,没有电面直接onsite。和HR通电话准备下一轮
•          20th Nov – 和工程师Coaching Call。介绍onsite内容,考核点,注意点
•          2nd Dec - Onsite
•          19th Dec – HR通知HC过
面试题
OA
10月的OA依然是那两道经典题。
1. Given a number(of type string, decimal) greater than or equal to 10, for each two adjacentdigits, take them out, calculate the average ((floor(a + b) /2 ) of them andput the digit back. Output the maximum possible value (of type string).
题目说明不需要考虑效率问题只需要考虑正确性,因此brute force,直接字符串操作就可以,不需要考虑字符串split和combine的效率问题。题目规定了数字大于等于10,因此边界条件也不太需要考虑。
2. LC 388 变种。题目要求可能不同(诸如输出包括文件名最长的路径,不包括文件名最长的路径,包括图片文件最长的路径等)。
具体方法是stack和dfs。扫描输入并对于每一个文件夹或文件计算出当前路径的长度,同时用另一个变量记录所有满足条件的最长的路径的长度。需要注意的是根目录的边界情况,因为题目要求根目录是”:\”,根目录下某一子目录的路径是”:\subdirectory”,所以实际上根目录比其他目录长度多1.
Onsite
1. 白人大叔。聊了聊专业,上过的课,介绍了一个project。开始做题。
Museum map: Given a map (oftype char[][]) of a museum where ‘.’ stands for an empty room, ‘G’ stands for aguardian and ‘L’ stands for a locked room. A guardian is able to reach neighboring(up, down, left, right) empty rooms in 1 move, but can not enter a locked room.Return how many moves the nearest guardian has to take to reach each emptyroom. The return value should be an int[][] whose size is the same as the inputmap. For an empty room mark the corresponding cell with -1 and for a guardianmark with -2.
讨论:地图是不是永远valid,是不是静态的,是不是可以放到内存里;guardian的数量相对于整个地图room的数量是不是trivial的。
回答:地图永远valid,静态的,可以放倒内存,guardian数量远远小于room的数量。
我的做法:一开始想法是对于每一个guardian做一次bfs,得到他到每一个room的距离,然后把所有guardian的bfs结果汇总,对于每一个room取最小值作为结果输出。面试官说可以让写code。
写完发现bfs中有一个变量有bug,经提示改正。面试官说code应该是对的,但是不够efficient。我说似乎可以在一开始把所有的guardian加到bfs的queue中,然后一次dfs就可以完成。面试官说可以。没有要写code。让我问了些问题,第一轮结束。
2. 白人大叔和白人小哥一起。
题目:Given the root directory of a file system (represented by an-ary tree), return all the directories and files (return as List<Node>).
讨论:具体的Node的表示方法,输入不合法需不需要handle等。
回答:可以用类似Leetcode那种方法表示,需要handle不合法输入(该情况下其实只是根节点是null)。
我的做法:用Queue implement一个BFS完成。
跟进 1: what if the file system has symbolic links? (i.e. the tree isnow a graph). 要求在原来的代码上进行修改。
我的做法:保存一个hashset表示已经访问过的节点避免重复。
跟进2: reconstructthe file system in another drive w/o the symbolic links (i.e. deep copy thetree)
我的做法:将上述hashset改为hashmap,key是原来的树里需要copy的节点,value是复制后的节点。依然用BFS进行deepcopy。
跟进3: What isthere are symbolic links? (i.e. deep copy the graph)?
讨论了一下做法,依然保留上述hashmap,如果hashmap中有的key-value-pair就不需要复制。没有需要写code。
3. 午饭。Google kirkland的食堂叫Hashtable,如果来面试的话里面的pad thai值得一试。
4. 国人大姐。聊了一下做过的project当中的难点,以及如何解决的。
题目:Given a sidewalk with length 100.0, and a stream of rain drops,assuming the length of a rain drop is 1.00 and the rain drop could fall randomly anywhere w/in the sidewalk, return the number of raindrops untilthe sidewalk is all wet.
讨论:raindrop stream是不是无限的,raindrop stream api的形式,raindrop会不会滴到sidewalk以外,区间开闭等。
回答:是无限,类似Iterator,不会滴到sidewalk以外,区间为闭区间。
我的做法:一开始不太有想法,想到是区间问题可能是用树比较合适,跟面试官讨论面试官说可以你先写写看(这里吐槽一下google的面试官,大多情况下只要我有想法都会说你开始写吧,而不会先讨论清楚具体怎么写)。写着写着发现用treemap确实可以写的通,用treemap存sidewalk上已经湿了的区间,其中key是区间左端点,value是区间右端点。对于新的raindrop调用treemap的api ceiling和floor找到左右区间,分类讨论看能不能和左右合并并分别处理。写完跟面试官交流,被面试官质疑分类有不完整的地方,检查了一下做了修改,和面试官讨论通过。
跟进1: 如何测试。
我的做法:新雨点不和旧区间overlap:raindrop左端点的位置依次是0.00, 1.00, 2.00…,返回值应该是100. 测试新雨点与左边区间overlap: raindrop左端点依次是0.00,0.10,0.20,…,返回值应该是1000. 测试新雨点与右边区间overlap:99.0, 98.5, 98.0 …;新雨点与旧雨点完全重合:0.00,0.00,1.00,1.00……等
跟进2: 时间空间复杂度
一开始我说时间是O(lgn), n是树里面的区间的个数,空间是O(n)。面试官说再看一看条件,发现树里面的区间不可能超过100个,因此时间空间复杂度都是O(1).
5. 国人大哥。聊了聊过去project中自己觉得最有意思的地方。
问题1: Giventhe root of a tree and a list of nodes that are about to be erased, return theforest (represented by a list of root nodes) after the erase.
我静静思考了几秒钟面试官立刻说你需要 think out loud. 于是开始胡言乱语说BFS,用Queue,又说erase好像不是很好操作,因为erase的节点的孩子还是要继续访问的,但是孩子又有可能是被erase的……可以在bfs出队的时候对孩子进行判断,但是又好像不太对……面试官看不下去了说你的想法应该可行,开始写code吧。写完拿了一个例子walk through可行。
跟进1: 如何测试。
我的回答:空树,[1,2,3]完全树根节点被erase,左子树根节点被erase,右子树根节点被erase,只有左子树左子树被erase等等。面试官说还需要测根和左子树都被erase。我说您说得对啊。
问题2: Given alist of Iterators, Design a class which implements the interface Iterator (i.e. include hasNext() and next()), which woulditerate through the iterators in a round-robin way. E.g., [[1, 2, 3], [4, 5, 6], [7, 8,9]], next() 依次输出1, 4, 7, 2, 5, 8, 3, 6, 9.
我的做法:存一个deque,每次next()从队首deque一个iterator,call这个iterator的next(), 如果空了就扔掉,还有下一个就再加到队尾。
跟进2: 如果还需要hasPrev()和 prev() 怎么办。
我说,那就反过来好了从后面deque从前面enqueue.面试官说不行,因为你有些iterator到头了就扔掉了。我说那不扔,他说还是不行,比如[[1, 2, 3], [4], [5, 6, 7]]就会有问题。我想了半天没听明白为啥接着问,他又解释了一遍我好像明白了,我说那再加一个variable表示iterator到了level,他说可以,没有写code。
总结:Google Kirkland的环境确实好,国人和白人很多,人也都很nice,做的project偏cloud和一些内部的technical support。整个组比较精干,work life balance 很好。但是headcount很少。HR已经通知我说今年没有hc所有office都只有MTV在招人了。作为本地人LZ还是想留在本地所以最近还在接着面本地其他厂。求好运o(≧v≦)o。

评分

参与人数 6大米 +70 收起 理由
Mr.Sagemaker + 3 很有用的信息!
Sissi_Lee + 3 楼主好用心
elizabethxiazhi + 3 感谢分享!
shayne93 + 1 谢谢你的介绍!
独魔圣剑 + 50 感谢分享!

查看全部评分


上一篇:亚马逊哦啊二跪经
下一篇:Glassdoor上一道bb的题

本帖被以下淘专辑推荐:

推荐
minggr 2017-1-6 12:45:12 | 只看该作者
全局:
Onsite 1, 一遍BFS
  1. struct point {
  2.     int x, y;

  3.     point(int a, int b): x(a), y(b) {}
  4. };

  5. vector<vector<int>> bfs(vector<vector<char>> &map)
  6. {
  7.     size_t row = map.size();
  8.     size_t col = map[0].size();

  9.     vector<vector<int>> result;
  10.     for (size_t i = 0; i < row; i++)
  11.         result.push_back(vector<int>(col));

  12.     queue<point> q;

  13.     for (size_t i = 0; i < row; i++) {
  14.         for (size_t j = 0; j < col; j++) {
  15.             if (map[i][j] == 'G') {
  16.                 point p(i, j);
  17.                 q.push(p);
  18.                 result[i][j] = -2;
  19.             }
  20.         }
  21.     }

  22.     //up, down, left, right
  23.     vector<vector<int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

  24.     int d = 1;
  25.     while (!q.empty()) {
  26.         size_t size = q.size();
  27.         for (size_t i = 0; i < size; i++) {
  28.             point p = q.front(); q.pop();

  29.             for (auto dir : directions) {
  30.                 int x = p.x + dir[0];
  31.                 int y = p.y + dir[1];

  32.                 if (x >= 0 && x < row && y >= 0 && y < col) {
  33.                     if (map[x][y] == '.') {
  34.                         if (result[x][y] == 0) {
  35.                             result[x][y] = d;
  36.                             q.push(point(x, y));
  37.                         }
  38.                     } else if (map[x][y] == 'L')
  39.                         result[x][y] = -1;
  40.                 }

  41.             }
  42.         }

  43.         d++;
  44.     }

  45.     return result;
  46. }

  47. int main()
  48. {
  49.     vector<vector<char>> map = {
  50.         {'G', 'L', 'L', '.'},
  51.         {'.', '.', 'G', '.'},
  52.         {'L', '.', 'L', '.'},
  53.         {'.', 'G', 'L', 'G'},
  54.         {'.', '.', '.', '.'},
  55.     };

  56.     vector<vector<int>> result = bfs(map);
  57.     for (size_t i = 0; i < result.size(); i++) {
  58.         for (size_t j = 0; j < result[0].size(); j++) {
  59.             cout << result[i][j] << " ";
  60.         }
  61.         cout << endl;
  62.     }

  63.     return 0;
  64. }
复制代码
回复

使用道具 举报

推荐
minggr 2017-1-5 14:24:23 | 只看该作者
全局:
写一个LC388的, 这现场真是很难写对
  1. class Solution {
  2. public:
  3.     int lengthLongestPath(string input) {
  4.         size_t i = 0;
  5.         int max_len = 0;
  6.         int cur_len = 0;
  7.         vector<int> levels;
  8.         bool is_file = false;
  9.         size_t indent = 0;

  10.         while (i < input.size()) {
  11.             if (input[i] == '\n') {
  12.                 i++; //skip '\n'

  13.                 int len = cur_len + 1;
  14.                 if (indent > 0)
  15.                     len += levels[indent-1];

  16.                 if (indent == levels.size())
  17.                     levels.push_back(len);
  18.                 else
  19.                     levels[indent] = len;

  20.                 if (is_file && len > max_len)
  21.                     max_len = len;

  22.                 cur_len = 0;
  23.                 is_file = false;
  24.                 indent = 0;

  25.                 while (i < input.size() && input[i] == '\t') {
  26.                     indent++;
  27.                     i++; //skip '\t'
  28.                 }
  29.             } else {
  30.                cur_len++;
  31.                if (input[i] == '.')
  32.                     is_file = true;
  33.                i++;
  34.             }
  35.         }

  36.         if (is_file) {
  37.             int len = levels[indent - 1] + cur_len;

  38.             max_len = max(len, max_len);
  39.         }

  40.         return max_len;
  41.     }
  42. };

  43. int main()
  44. {
  45.     Solution s;

  46.     string input = "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdir1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext";

  47.     cout << s.lengthLongestPath(input) << endl;

  48.     return 0;
  49. }
复制代码
回复

使用道具 举报

推荐
minggr 2017-1-4 14:44:38 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
wtcupup 2017-1-4 13:52:45 | 只看该作者
全局:
第二轮 “可以用类似Leetcode那种方法表示” 具体是leetcode哪一题啊?
回复

使用道具 举报

🔗
 楼主| mhyi 2017-1-4 13:56:35 | 只看该作者
全局:
wtcupup 发表于 2017-1-4 13:52
第二轮 “可以用类似Leetcode那种方法表示” 具体是leetcode哪一题啊?

说的是Leetcode对树的节点的表示方法哈,
class Node {
    String name;
    Node[] next;
}
这样。
回复

使用道具 举报

🔗
独魔圣剑 2017-1-4 13:58:02 | 只看该作者
全局:
这我学弟,特意来支持一下
回复

使用道具 举报

🔗
 楼主| mhyi 2017-1-4 14:02:41 | 只看该作者
全局:
独魔圣剑 发表于 2017-1-4 13:58
这我学弟,特意来支持一下

学~~~~长~~~~
回复

使用道具 举报

🔗
momoly27 2017-1-4 14:19:51 | 只看该作者
全局:
大师我来支持你啦!!!!
回复

使用道具 举报

🔗
minggr 2017-1-4 14:23:07 | 只看该作者
全局:
OA第1题是如下这么个意思吗?

比如: 3208,有3种可能
1. floor((3+2)/2) = 2, 得208
2. floor((2+0)/2) = 1, 得318
3. floor((0+8)/2) = 4, 得324

所以最大可能值是324
回复

使用道具 举报

🔗
 楼主| mhyi 2017-1-4 14:35:25 | 只看该作者
全局:
minggr 发表于 2017-1-4 14:23
OA第1题是如下这么个意思吗?

比如: 3208,有3种可能

恩对的哈
回复

使用道具 举报

🔗
 楼主| mhyi 2017-1-4 14:37:10 | 只看该作者
全局:
momoly27 发表于 2017-1-4 14:19
大师我来支持你啦!!!!

刷题小分队加油!
回复

使用道具 举报

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

本版积分规则

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