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

google footer level 4,送foobar challenge链接

🔗
匿名用户-BSQTA  2017-7-3 10:09:49 |倒序浏览

2017(4-6月) 码农类General 硕士 全职@google - Other - 在线笔试  | | Pass | 在职跳槽

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

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

x
关于google foobar这个博主介绍得很好: 我有好几题和他重复。贴一个遇到的level4题和我的解法。感觉gg foobar就是加点mathmatics的经典算法,high performance的implementation有难度,没有acm难。之后会贴个level5的新题。另外拿到个foobar challenge链接,想要的加米站内信,先到先得。如果要面试的话内推显然更快,主要是好玩。Free the Bunny Prisoners
========================

You need to free the bunny prisoners before Commander Lambda's space station explodes! Unfortunately, the commander was very careful with her highest-value prisoners - they're all held in separate, maximum-security cells. The cells are opened by putting keys into each console, then pressing the open button on each console simultaneously. When the open button is pressed, each key opens its corresponding lock on the cell. So, the union of the keys in all of the consoles must be all of the keys. The scheme may require multiple copies of one key given to different minions.

The consoles are far enough apart that a separate minion is needed for each one. Fortunately, you have already freed some bunnies to aid you - and even better, you were able to steal the keys while you were working as Commander Lambda's assistant. The problem is, you don't know which keys to use at which consoles. The consoles are programmed to know which keys each minion had, to prevent someone from just stealing all of the keys and using them blindly. There are signs by the consoles saying how many mi
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
t-size:12px">    (int) num_required = 3

Output:
    (int) [[0, 1, 2, 3, 4, 5], [0, 1, 2, 6, 7, 8], [0, 3, 4, 6, 7, 9], [1, 3, 5, 6, 8, 9], [2, 4, 5, 7, 8, 9]]

Inputs:
    (int) num_buns = 4
    (int) num_required = 4
Output:
    (int) [[0], [1], [2], [3]]




上一篇:六月Yelp Oniste, 求米~
下一篇:A9 phone screen
地里匿名用户
🔗
匿名用户-BSQTA  2017-7-3 10:18:38
想法是这个: https://en.wikipedia.org/wiki/Combination
  1. public class Answer {

  2.   public static int[][] answer(int num_buns, int num_required) {

  3.     if(num_required > num_buns || num_required == 0) return new int[num_buns][0];

  4.     if(num_required == 1) return new int[num_buns][1];

  5.    

  6.     int[] bun_labels = new int[num_buns];

  7.     int combSize = num_buns - num_required + 1;

  8.     for(int i = 0; i < num_buns; i++) bun_labels[i] = i;

  9.     List<List<Integer>> schema = getCombinations(bun_labels, combSize, 0);

  10.    

  11.     List<List<Integer>> result = new ArrayList<List<Integer>>();

  12.     for(int j = 0; j < num_buns; j++) result.add(new ArrayList<Integer>());

  13.    

  14.     for(int k = 0; k < schema.size(); k++) {

  15.         List<Integer> positions = schema.get(k);

  16.         for(int pos : positions) {

  17.           result.get(pos).add(k);

  18.         }

  19.     }

  20.    

  21.     int[][] ans = new int[num_buns][result.get(0).size()];

  22.     for(int c = 0; c < result.size(); c++) {

  23.         List<Integer> cur = result.get(c);

  24.         for(int m = 0; m < cur.size(); m++) ans[c][m] = cur.get(m);

  25.     }

  26.     return ans;

  27. }



  28. private static List<List<Integer>> getCombinations(int[] items, int combSize, int startIndx) {

  29.     List<List<Integer>> result = new ArrayList<List<Integer>>();

  30.     if (combSize == 0) return result;

  31.     if (combSize == 1) {

  32.         for(int i = startIndx; i < items.length; i++) {

  33.             List<Integer> cur = new ArrayList<Integer>();

  34.             cur.add(items[i]);

  35.             result.add(cur);

  36.         }

  37.     } else {

  38.         for(int i = startIndx; i <= items.length - combSize; i++){

  39.             List<List<Integer>> cur = getCombinations(items, combSize-1, i+1);

  40.             for (List<Integer> ele : cur) {

  41.                 ele.add(0, i);

  42.             }

  43.             result.addAll(cur);

  44.         }

  45.     }

  46.     return result;

  47. }

  48. }
复制代码
回复

使用道具 举报

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

本版积分规则

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