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

Google Onsite面经

全局:

2017(1-3月) 码农类General 硕士 全职@google - 内推 - Onsite  | | Fail | 在职跳槽

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

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

x
分享一下1月底在kirkland 的onsite 挂经,整体感觉题难度属于medium以上。欢迎大家讨论!

1. LC 340; Follow up, what if the input is a stream? Can you make the space cost less?

2. Give a set of nodes in a hidden double linked list, return the number of connected components in the set.

        Follow up, what if we change the double linked list into single linked list?

3. Check if a matrix is a to
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
).


        Example:
                                                                current        high         low
                        update(1, 5)                5                           5                        5
                        update(2, 8)                8                           8                        5
                        update(1, 10)                8                           10                        8
                        delete(2)                        10                           10                        10

评分

参与人数 3大米 +12 收起 理由
knight0clk + 4 感谢分享!
dobbin + 3 感谢分享!
Zhenying + 5 谢谢你的介绍!

查看全部评分


上一篇:热乎乎palantir OA 求大米~~~
下一篇:Google Phone Call求问

本帖被以下淘专辑推荐:

推荐
erty 2017-2-23 06:16:22 | 只看该作者
全局:
第五题参考各位的意见写了代码,求指正
  1. public static class Stock{

  2.   public TreeMap<Integer, Integer> priceMap;
  3.   public TreeMap<Integer, Integer> countMap;

  4.   public Stock(){
  5.     priceMap = new TreeMap<Integer, Integer>();  //key is the timestamp and value is the price
  6.     countMap = new TreeMap<Integer, Integer>();  // key is the price and value is the number of the price
  7.   }

  8.   // update(timestamp t2, price): timestamp can be an old one or a new one.
  9.   public void update(int timestamp, int price){
  10.     if(priceMap.containsKey(timestamp)){
  11.       int origin = priceMap.get(timestamp);
  12.       if(countMap.get(origin) == 1) countMap.remove(origin);
  13.       else countMap.put(origin, countMap.get(origin) - 1);
  14.     }
  15.     priceMap.put(timestamp, price);
  16.     countMap.put(price, countMap.getOrDefault(price, 0) + 1);
  17.   }

  18.   //delete(timestamp t1): delete the data at timestamp t1
  19.   public void delete(int timestamp){
  20.     if(! priceMap.containsKey(timestamp)) return ;
  21.     int price = priceMap.get(timestamp);
  22.     if(countMap.get(price) == 1) countMap.remove(price);
  23.     else countMap.put(price, countMap.get(price) - 1);
  24.     priceMap.remove(timestamp);
  25.   }

  26.   public int getCurrentPrice(){
  27.     if(priceMap.size() == 0) return -1;
  28.     else return priceMap.lastEntry().getValue();
  29.   }

  30.   public int getHighPrice(){
  31.     if(countMap.size() == 0) return -1;
  32.     else return countMap.lastKey();
  33.   }

  34.   public int getLowPrice(){
  35.     if(countMap.size() == 0) return -1;
  36.     else return countMap.firstKey();
  37.   }
  38. }
复制代码
回复

使用道具 举报

推荐
bigbearlake 2017-3-27 01:08:10 | 只看该作者
全局:
组合contacts,建图的方法
  1. public class GroupContactsII {
  2.     static class Contact {
  3.         String name;
  4.         List<String> emails;

  5.         public Contact(String n, List<String> es) {
  6.             name = n;
  7.             emails = es;
  8.         }
  9.     }
  10.     public int unionUsername(List<Contact> input) {
  11.         if (input == null || input.size() == 0) {
  12.             return 0;
  13.         }

  14.         int[][] graph = buildGraph(input);
  15.         boolean[] visited = new boolean[input.size()];
  16.         int res = 0;
  17.         for (int i = 0; i < input.size(); i++) {
  18.             if (!visited[i]) {
  19.                 dfs(graph, i, visited);
  20.                 res++;
  21.             }
  22.         }

  23.         return res;
  24.     }

  25.     private void dfs(int[][] graph, int k, boolean[] visited) {
  26.         if (visited[k]) {
  27.             return;
  28.         }

  29.         visited[k] = true;
  30.         for (int i = 0; i < graph.length; i++) {
  31.             if (graph[k][i] == 1) {
  32.                 dfs(graph, i, visited);
  33.             }
  34.         }
  35.     }

  36.     public int[][] buildGraph(List<Contact> input) {
  37.         int n = input.size();
  38.         int[][] graph = new int[n][n];

  39.         HashMap<String, List<Integer>> map = new HashMap();
  40.         for (int i = 0; i < input.size(); i++) {
  41.             for (String s : input.get(i).emails) {
  42.                 if (!map.containsKey(s)) {
  43.                     map.put(s, new ArrayList<>());
  44.                 }
  45.                 map.get(s).add(i);
  46.             }
  47.         }

  48.         for (List<Integer> list : map.values()) {
  49.             for (int i = 0; i < list.size(); i++) {
  50.                 for (int j = i + 1; j < list.size(); j++) {
  51.                     graph[list.get(i)][list.get(j)] = 1;
  52.                     graph[list.get(j)][list.get(i)] = 1;
  53.                 }
  54.             }
  55.         }

  56.         return graph;
  57.     }

  58.     public static void main(String[] args) {
  59.         GroupContactsII u = new GroupContactsII();
  60.         List<Contact> input = new ArrayList<>();
  61.         input.add(new Contact("Jack1", Arrays.asList("123@gmail.com", "ggg@gmail.com")));
  62.         input.add(new Contact("Jack2", Arrays.asList("hh@gmail.com", "fff@gmail.com")));
  63.         input.add(new Contact("Bob", Arrays.asList("123@gmail.com", "eeegg@gmail.com")));
  64.         input.add(new Contact("Jack4", Arrays.asList("ccc@gmail.com", "aaa@gmail.com")));
  65.         input.add(new Contact("Jack5", Arrays.asList("efg@gmail.com", "ccc@gmail.com")));
  66.         System.out.println(u.unionUsername(input));
  67.     }
  68. }
复制代码
回复

使用道具 举报

推荐
bigbearlake 2017-3-26 16:19:42 | 只看该作者
全局:
第四题代码 union find ,另一种方法是建一个图,然后dfs
  1. public class UserFindByEmail {

  2.     static class Contact {
  3.         String name;
  4.         List<String> emails;

  5.         public Contact(String n, List<String> es) {
  6.             name = n;
  7.             emails = es;
  8.         }
  9.     }
  10.     public int unionUsername(List<Contact> input) {
  11.         if (input == null || input.size() == 0) {
  12.             return 0;
  13.         }

  14.         int[] roots = new int[input.size()];
  15.         HashMap<String, List<Integer>> map = new HashMap<>();
  16.         int n = input.size();
  17.         for (int i = 0; i < n; i++) {
  18.             roots[i] = i;
  19.         }

  20.         for (int i = 0; i < input.size(); i++) {
  21.             Contact user = input.get(i);
  22.             for (String email : user.emails) {
  23.                 if (!map.containsKey(email)) {
  24.                     map.put(email, new ArrayList<>());
  25.                 }
  26.                 map.get(email).add(i);
  27.             }
  28.         }

  29.         for (List<Integer> list : map.values()) {
  30.             for (int i = 0; i < list.size() - 1; i++) {
  31.                 union(roots, list.get(0), list.get(1));
  32.             }
  33.         }

  34.         int res = 0;
  35.         for (int i = 0; i < roots.length; i++) {
  36.             if (roots[i] == i) {
  37.                 res++;
  38.             }
  39.         }

  40.         return res;
  41.     }

  42.     public void union(int[] roots, int i, int j) {
  43.         int x = find(roots, i);
  44.         int y = find(roots, j);
  45.         roots[x] = y;
  46.     }

  47.     public int find(int[] roots, int x) {
  48.         while (roots[x] != x) {
  49.             roots[x] = roots[roots[x]];
  50.             x = roots[x];
  51.         }

  52.         return x;
  53.     }

  54.     public static void main(String[] args) {
  55.         UserFindByEmail u = new UserFindByEmail();
  56.         List<Contact> input = new ArrayList<>();
  57.         input.add(new Contact("Jack1", Arrays.asList("123@gmail.com", "ggg@gmail.com")));
  58.         input.add(new Contact("Jack2", Arrays.asList("hh@gmail.com", "fff@gmail.com")));
  59.         input.add(new Contact("Bob", Arrays.asList("123@gmail.com", "eeegg@gmail.com")));
  60.         input.add(new Contact("Jack4", Arrays.asList("ccc@gmail.com", "aaa@gmail.com")));
  61.         input.add(new Contact("Jack5", Arrays.asList("efg@gmail.com", "ccc@gmail.com")));
  62.         System.out.println(u.unionUsername(input));
  63.     }
  64. }
复制代码
回复

使用道具 举报

🔗
YY大帝 2017-2-19 11:28:40 | 只看该作者
全局:
感谢LZ分享,求问第五题设计的思路,要用到heap吗
回复

使用道具 举报

🔗
say543 2017-2-19 14:54:30 | 只看该作者
全局:
第一题 follow up 因该药的是hashMap<Character, lastHappenIndex> 这样的space reduction 事吗?
回复

使用道具 举报

🔗
say543 2017-2-19 15:04:09 | 只看该作者
全局:
第五题 感觉用hashHeap 因该可行? current 指的是timestamp 最新的price 这样吗?
回复

使用道具 举报

🔗
say543 2017-2-19 15:12:36 | 只看该作者
全局:
第四题两两check if a 包含b 建立edge a-> b 形成一个DAG group 然后用BFS 从indeg = 0 的点 看几个connected component?
回复

使用道具 举报

🔗
nestwood 2017-2-20 05:39:19 | 只看该作者
全局:
第2题,单链,只要有一个removed的set,就可以不用反转单链了吧?
回复

使用道具 举报

🔗
nestwood 2017-2-20 05:49:05 | 只看该作者
全局:
nestwood 发表于 2017-2-20 05:39
第2题,单链,只要有一个removed的set,就可以不用反转单链了吧?

胡说了,比这要复杂
回复

使用道具 举报

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

使用道具 举报

🔗
Zhenying 2017-2-20 10:02:12 | 只看该作者
全局:
感谢楼主分享。请问楼主第4题有什么好方法么?我只能想到O(n^2)的暴力解法。
回复

使用道具 举报

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

使用道具 举报

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

本版积分规则

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