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

Google Onsite

全局:

2015(10-12月) 码农类General 硕士 全职@google - Other - Onsite  | | Other | 在职跳槽

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

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

x
这周2面的,现在在等结果,面得其实不好,recruiter说这周末或者下周初给我update,所以现在感到特别煎熬。。。发个面筋,希望能帮到大家,也希望大家能bless我拿到offer。
其实题目都不难,可能是因为我是在职的原因。
我就不写我的做法了,现在心里太乱了。。。

1. 第一轮是写一个bounded bloc
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
pass,我的最初解是two pass,所以two pass写到一半他就说让写one pass的。写one pass的时候有bug,被指出来后,想到一个方法,面试官说是对的,不过不是面试官希望的。最后也没能写完,感到特别无力。。。


上一篇:G家拿到TeamMatch于是来回馈地里
下一篇:Amazon 12/10 OA

本帖被以下淘专辑推荐:

全局:
写了下打印树的题,最后输出格式还是有一些差异
  1. public class PrintStructrue {

  2.         public static void main(String[] args) {
  3.                 PrintStructrue ps = new PrintStructrue();
  4.                 int[][] edges = { { 7, 6 }, { 7, 5 }, { 7, 4 }, { 6, 3 }, { 6, 2 } };
  5.                 ps.printStructure(edges);
  6.         }

  7.         public void printStructure(int[][] edges) {
  8.                 if (edges == null || edges.length == 0) {
  9.                         return;
  10.                 }
  11.                 HashMap<Integer, HashSet<Integer>> graph = buildGraph(edges);
  12.                 HashMap<Integer, Integer> counter = new HashMap<Integer, Integer>();
  13.                 for (HashSet<Integer> set : graph.values()) {
  14.                         for (int ele : set) {
  15.                                 if (counter.containsKey(ele)) {
  16.                                         counter.put(ele, counter.get(ele) + 1);
  17.                                 } else {
  18.                                         counter.put(ele, 1);
  19.                                 }
  20.                         }
  21.                 }
  22.                 Queue<Integer> queue = new LinkedList<Integer>();
  23.                 for (int ele : graph.keySet()) {
  24.                         if (!counter.containsKey(ele)) {
  25.                                 queue.offer(ele);
  26.                         }
  27.                 }
  28.                 while (!queue.isEmpty()) {
  29.                         int val = queue.poll();
  30.                         print(val, graph, 0);
  31.                 }
  32.         }

  33.         private void print(int val, HashMap<Integer, HashSet<Integer>> graph,
  34.                         int len) {
  35.                 for (int i = 0; i < len; i++) {
  36.                         if (i == 0) {
  37.                                 System.out.print(" ");
  38.                         }
  39.                         System.out.print("-");
  40.                 }
  41.                 System.out.println(val);
  42.                 for (int i : graph.get(val)) {
  43.                         print(i, graph, len + 1);
  44.                 }
  45.         }

  46.         private HashMap<Integer, HashSet<Integer>> buildGraph(int[][] edges) {
  47.                 HashMap<Integer, HashSet<Integer>> map = new HashMap<Integer, HashSet<Integer>>();
  48.                 for (int[] edge : edges) {
  49.                         if (!map.containsKey(edge[0])) {
  50.                                 map.put(edge[0], new HashSet<Integer>());
  51.                         }
  52.                         if (!map.containsKey(edge[1])) {
  53.                                 map.put(edge[1], new HashSet<Integer>());
  54.                         }
  55.                         map.get(edge[0]).add(edge[1]);
  56.                 }
  57.                 return map;
  58.         }
  59. }
复制代码
回复

使用道具 举报

全局:
coin题,假设每个硬币只能用一次
  1. public class CoinsChangeIII {

  2.         public static void main(String[] args) {
  3.                 int[] coins = { 1, 2, 3, 4, 5, 6, 10 };
  4.                 List<Integer> res = minChange(coins, 9);
  5.                 for (int i : res) {
  6.                         System.out.print(i + " ");
  7.                 }
  8.         }

  9.         public static List<Integer> minChange(int[] coins, int num) {
  10.                 int[] table = new int[num + 1];
  11.                 int[] solution = new int[num + 1];
  12.                 Arrays.fill(table, Integer.MAX_VALUE);
  13.                 table[0] = 0;
  14.                 for (int i = 0; i < coins.length; i++) {
  15.                         for (int j = num; j > 0; j--) {
  16.                                 if (j >= coins[i] && table[j - coins[i]] != Integer.MAX_VALUE ) {
  17.                                         if (table[j - coins[i]] + 1 < table[j]) {
  18.                                                 table[j] = table[j - coins[i]] + 1;
  19.                                                 solution[j] = i;
  20.                                         }
  21.                                 }
  22.                         }
  23.                 }
  24.                
  25.                 List<Integer> res = new ArrayList<Integer>();
  26.                 if (table[num] == Integer.MAX_VALUE) {
  27.                         return res;
  28.                 }
  29.                 while (num > 0) {
  30.                         res.add(coins[solution[num]]);
  31.                         num -= coins[solution[num]];
  32.                 }
  33.                 Collections.reverse(res);
  34.                 return res;

  35.         }
  36. }
复制代码
回复

使用道具 举报

全局:
coin题,假设每个硬币可以用多次
  1. public class CoinsChangeII {

  2.         public static void main(String[] args) {
  3.                 int[] coins = { 1, 4, 5, 10 };
  4.                 List<Integer> res = minChange(coins, 8);
  5.                 for (int i : res) {
  6.                         System.out.print(i + " ");
  7.                 }
  8.         }

  9.         public static List<Integer> minChange(int[] coins, int num) {
  10.                 int[] table = new int[num + 1];
  11.                 int[] solution = new int[num + 1];
  12.                 for (int i = 1; i <= num; i++) {
  13.                         int minNum = Integer.MAX_VALUE;
  14.                         int minIndex = Integer.MAX_VALUE;
  15.                         for (int j = 0; j < coins.length; j++) {
  16.                                 if (coins[j] <= i && 1 + table[i - coins[j]] < minNum) {
  17.                                         minNum = 1 + table[i - coins[j]];
  18.                                         minIndex = j;
  19.                                 }
  20.                         }
  21.                         table[i] = minNum;
  22.                         solution[i] = minIndex;
  23.                 }

  24.                 List<Integer> res = new ArrayList<Integer>();
  25.                 if (table[num] == Integer.MAX_VALUE) {
  26.                         return res;
  27.                 }
  28.                 while (num > 0) {
  29.                         res.add(coins[solution[num]]);
  30.                         num -= coins[solution[num]];
  31.                 }

  32.                 return res;

  33.         }
  34. }
复制代码
回复

使用道具 举报

🔗
hyliu0000 2015-12-11 02:42:24 | 只看该作者
全局:
第三题感觉是不是应该利用hashmap《int, node》建立起来一个树?然后再遍历一下?
回复

使用道具 举报

🔗
xiaoniuona 2015-12-12 08:46:18 | 只看该作者
全局:
谢谢楼主分享~请问A-B和B-A那题应该怎么做哈?
回复

使用道具 举报

🔗
abysshades 2015-12-12 12:19:52 | 只看该作者
全局:
跟楼主同一天哎,HR也跟我说下周一之前给update。。。莫非周二上午9:30左右在building 41见过的么?
回复

使用道具 举报

🔗
LifeGoesOn 2015-12-12 13:43:40 | 只看该作者
全局:
楼主 请问第5题怎么做到1 pass,我能想到的是把每个target sum对应最后一步要选的coin记录下来, 最后从后往前拿出所有的coin

补充内容 (2015-12-12 13:43):
这么做其实就是2pass了吗

回复

使用道具 举报

🔗
yjfox 2015-12-13 11:59:03 | 只看该作者
全局:
请问找硬币具体题目是?
回复

使用道具 举报

🔗
orangepie 2015-12-13 14:03:32 | 只看该作者
全局:
请问楼主 第四题两个list 那道题,  除了sort, 或者用set直接做; 还有什么更好地办法吗?
回复

使用道具 举报

🔗
shuishuimiao 2015-12-13 14:47:54 | 只看该作者
全局:
请问楼主能详细说一下找硬币这个题的题目吗
回复

使用道具 举报

🔗
杰西Jesse 2015-12-28 00:53:47 | 只看该作者
全局:
LifeGoesOn 发表于 2015-12-12 13:43
楼主 请问第5题怎么做到1 pass,我能想到的是把每个target sum对应最后一步要选的coin记录下来, 最后从后 ...

表示不理解题目诶0。0 怎么记录target sum呢~。谢谢
回复

使用道具 举报

🔗
kinggarden2001 2015-12-28 01:52:41 | 只看该作者
全局:
leetcode昨天刚加了这个题 用dp算最少个数 同时cache每步的最优解 最后应该能同时得出最少个数以及是哪些硬币 one pass
回复

使用道具 举报

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

本版积分规则

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