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

Google面经

全局:

2019(7-9月) 码农类General 硕士 全职@google - 实习ReturnOffer - Onsite  | | Other | 应届毕业生

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

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

x
gg onsite面经

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


求加米啊,谢谢大家🙏

评分

参与人数 6大米 +15 收起 理由
MiGTeddyBear + 1 很有用的信息!
tommyjiang + 1 很有用的信息!
MercyAPDY + 1 赞一个
cocoonsyd + 1 给你点个赞!
匿名用户-9XCTH + 10

查看全部评分


上一篇:高盛 engineering oa+hirevue
下一篇:Factual OA
推荐
wozm 2019-9-20 16:17:51 | 只看该作者
全局:
wozm 发表于 2019-9-20 16:09
用一个arrayList来装prefix product,注意每次遇到0就跳过。 用另一个arrayList来装0的个数。查的时候先查 ...
  1. public class LastKElementsProduction {
  2.     List<Integer> preProduct = new ArrayList<>();
  3.         List<Integer> num0 = new ArrayList<>();

  4.     public void add(int i){
  5.         if(i == 0) {
  6.                         preProduct.add(preProduct.size() == 0 ? 1 : preProduct.get(preProduct.size() - 1));
  7.                         num0.add(num0.size() == 0 ? 1 : num0.get(num0.size() - 1) + 1);
  8.                 } else {
  9.                         preProduct.add(preProduct.size() == 0 ? i : i * preProduct.get(preProduct.size() - 1));
  10.                         num0.add(num0.size() == 0 ? 0 : num0.get(num0.size() - 1) + 1);
  11.                 }
  12.     }

  13.     public int get(int k){
  14.         int size = preProduct.size();
  15.                 int start = Math.max(size - k, 0);
  16.                 if(num0.get(size - 1) - num0.get(start) == 0) {
  17.                         return preProduct.get(size - 1) / preProduct.get(start);
  18.                 } else {
  19.                         return 0;
  20.                 }
  21.     }

  22.     public static void main(String[] args){
  23.         LastKElementsProduction test = new LastKElementsProduction();
  24.         test.add(3);
  25.         test.add(-5);
  26.         test.add(6);
  27.         test.add(9);
  28.         test.add(3);
  29.         System.out.println(test.get(6));
  30.     }
  31. }
复制代码
回复

使用道具 举报

推荐
wozm 2019-9-20 16:09:29 | 只看该作者
全局:
用一个arrayList来装prefix product,注意每次遇到0就跳过。 用另一个arrayList来装0的个数。查的时候先查查0的个数,右端点减左端点>0就返回0,否则就返回prefix product右端点除以左端点。

评分

参与人数 1大米 +3 收起 理由
acthy + 3 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
case4sean 2019-9-12 09:35:28 | 只看该作者
全局:
碰到简单题,现场跟面试官跑了一边,当场觉得没问题,然后开始聊天。回来自己想想好像有bug,跑不过corner case,不知道面试官回头再去看一遍。:(
回复

使用道具 举报

🔗
zezed 2019-9-12 09:41:55 | 只看该作者
全局:
楼主请问下, 这个k可变是不是不能用sliding window的方法降低复杂度了?
回复

使用道具 举报

🔗
jemi 2019-9-13 02:06:54 | 只看该作者
全局:
这个solution可以吗,有没有更好的?
  1. public class LastKElementsProduction {
  2.     List<Integer> list = new ArrayList<>();
  3.     int all = 1;

  4.     public void add(int i){
  5.         list.add(i);
  6.         all *= i;
  7.     }

  8.     public int get(int k){
  9.         int total = 1;
  10.         int n = list.size();
  11.         if(n < k) return -1;
  12.         if(k >= n/2){
  13.             total = all;
  14.             for(int i = 0; i < (n-k); i++){
  15.                 total /= list.get(i);
  16.             }
  17.         }else{
  18.             for(int i = 0, j = n - 1; i < k ; i++, j--){
  19.                 total *= list.get(j);
  20.             }
  21.         }
  22.         return total;
  23.     }

  24.     public static void main(String[] args){
  25.         LastKElementsProduction test = new LastKElementsProduction();
  26.         test.add(3);
  27.         test.add(-5);
  28.         test.add(6);
  29.         test.add(9);
  30.         test.add(3);
  31.         System.out.println(test.get(6));
  32.     }
  33. }
复制代码
回复

使用道具 举报

🔗
jemi 2019-9-13 02:39:04 | 只看该作者
全局:
想到了个更好的方法,思路来自利口 rangeSumQuery
  1. public class LastKElementsProduction {
  2.     Map<Integer, Integer> map = new HashMap<>();
  3.     int all = 1;

  4.     public void add(int i){
  5.         all *= i;
  6.         map.put(map.size()+1, all);
  7.     }

  8.     public int get(int k){
  9.         int m = map.size();
  10.         if(m == k) return all;
  11.         if(k > m) return -1;
  12.         return all / map.get(m-k);
  13.     }

  14.     public static void main(String[] args){
  15.         LastKElementsProduction test = new LastKElementsProduction();
  16.         test.add(3);
  17.         test.add(-5);
  18.         test.add(6);
  19.         test.add(9);
  20.         test.add(3);
  21.         System.out.println(test.get(3));
  22.     }
  23. }
复制代码
回复

使用道具 举报

🔗
case4sean 2019-9-13 03:37:03 | 只看该作者
全局:
jemi 发表于 2019-9-13 02:39
想到了个更好的方法,思路来自利口 rangeSumQuery[mw_shl_code=java,true]public class LastKElementsProdu ...

你这个没考虑 0 的情况
回复

使用道具 举报

全局:
请问楼楼onsite只面了一道题吗
回复

使用道具 举报

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

本版积分规则

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