San Jose各个房价 <1.5m 区域买房总结

一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投
内推多家公司面试
坐标湾区
Games Startup
招聘游戏开发工程师
游戏初创公司招聘工程师、UIUX Designer和游戏策划
把贵司招聘信息放这里
查看: 1425|回复: 1
收起左侧

google footer level 4,送foobar challenge链接

[复制链接] |试试Instant~ |关注本帖
9oooop 发表于 2017-7-3 10:09:49 | 显示全部楼层 |阅读模式

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

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

您需要 登录 才可以下载或查看,没有帐号?Sign Up 注册获取更多干货

x
关于google foobar这个博主介绍得很好:http://xiaohanyu.me/posts/2017-04-30-google-foobar-interview/ 我有好几题和他重复。贴一个遇到的level4题和我的解法。感觉gg foobar就是加点mathmatics的经典算法,high performance的implementation有难度,没有acm难。之后会贴个level5的新题。另外拿到个foobar challenge链接,想要的加米站内信,先到先得。如果要面试的话内推显然更快,主要是好玩。stem-font">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 minions had some keys for the set of consoles. You suspect that Commander Lambda has a systematic way to decide which keys to give to each minion such that they could use the consoles.
-google 1point3acres
You need to figure out the scheme that Commander Lambda used to distribute the keys. You know how many minions had keys, and how many consoles are by each cell. You know that Command Lambda wouldn't issue more keys than necessary (beyond what the key distribution scheme requires), and that you need as many bunnies with keys as there are consoles to open the cell.

Given the number of bunnies available and the number of locks required to open a cell, write a function answer(num_buns, num_required) which returns a specification of how to distribute the keys such that any num_required bunnies can open the locks, but no group of (num_required - 1) bunnies can.. 1point3acres

Each lock is numbered starting from 0. The keys are numbered the same as the lock they open (so for a duplicate key, the number will repeat, since it opens the same lock). For a given bunny, the keys they get is represented as a sorted list of the numbers for the keys. To cover all of the bunnies, the final answer is represented by a sorted list of each individual bunny's list of keys. Find the lexicographically least such key distribution - that is, the first bunny should have keys sequentially starting from 0.. more info on 1point3acres

num_buns will always be between 1 and 9, and num_required will always be between 0 and 9 (both inclusive). For example, if you had 3 bunnies and required only 1 of them to open the cell, you would give each bunny the same key such that any of the 3 of them would be able to open it, like so:
[
[0],
[0],
[0],
]. 1point 3acres 论坛
If you had 2 bunnies and required both of them to open the cell, they would receive different keys (otherwise they wouldn't both actually be required), and your answer would be as follows:
[
[0],. more info on 1point3acres
[1],.留学论坛-一亩-三分地
]
Finally, if you had 3 bunnies and required 2 of them to open the cell, then any 2 of the 3 bunnies should have all of the keys necessary to open the cell, but no single bunny would be able to do it. Thus, the answer would be:
[. From 1point 3acres bbs
[0, 1],
[0, 2],
[1, 2],
]

.本文原创自1point3acres论坛
Languages
=========

To provide a Python solution, edit solution.py
To provide a Java solution, edit solution.java

Test cases
==========

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

Inputs:
    (int) num_buns = 5
    (int) num_required = 3-google 1point3acres
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]]

. 围观我们@1point 3 acres

 楼主| 9oooop 发表于 2017-7-3 10:18:38 | 显示全部楼层
想法是这个: https://en.wikipedia.org/wiki/Combination
  1. public class Answer {
  2. . 1point3acres
  3.   public static int[][] answer(int num_buns, int num_required) { . from: 1point3acres

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

  5.     if(num_required == 1) return new int[num_buns][1];. From 1point 3acres bbs

  6.    

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

  8.     int combSize = num_buns - num_required + 1;

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

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

  11.    

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

  13.     for(int j = 0; j < num_buns; j++) result.add(new ArrayList<Integer>());.本文原创自1point3acres论坛

  14.    

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

  16. 来源一亩.三分地论坛.
  17.         List<Integer> positions = schema.get(k);

  18.         for(int pos : positions) {

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

  20.         }

  21.     }

  22.    

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

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

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

  26.         for(int m = 0; m < cur.size(); m++) ans[c][m] = cur.get(m);.本文原创自1point3acres论坛

  27.     }

  28.     return ans;

  29. }


  30. 来源一亩.三分地论坛.
  31. private static List<List<Integer>> getCombinations(int[] items, int combSize, int startIndx) {

  32.     List<List<Integer>> result = new ArrayList<List<Integer>>();. 一亩-三分-地,独家发布

  33.     if (combSize == 0) return result;.1point3acres网

  34.     if (combSize == 1) {

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

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

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

  38.             result.add(cur);

  39.         }

  40.     } else {

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

  42.             List<List<Integer>> cur = getCombinations(items, combSize-1, i+1);. Waral 博客有更多文章,
  43. . 一亩-三分-地,独家发布
  44.             for (List<Integer> ele : cur) {

  45.                 ele.add(0, i);
  46. . 牛人云集,一亩三分地
  47.             }

  48.             result.addAll(cur);
  49. . 1point 3acres 论坛
  50.         }

  51.     }

  52.     return result;
  53. . visit 1point3acres for more.
  54. }

  55. }
复制代码
回复 支持 反对

使用道具 举报

本版积分规则

提醒:发帖可以选择内容隐藏,部分板块支持匿名发帖。请认真读完以下全部说明:

■隐藏内容方法: [hide=200]你想要隐藏的内容比如面经[/hide]
■意思是:用户积分低于200则看不到被隐藏的内容
■可以自行设置积分值,不建议太高(200以上太多人看不到),也不建议太低(那就没必要隐藏了)
■建议只隐藏关键内容,比如具体的面试题目、涉及隐私的信息,大部分内容没必要隐藏。
■微信/QQ/电子邮件等,为防止将来被骚扰甚至人肉,以论坛私信方式发给对方最安全。
■匿名发帖的板块和方法:http://www.1point3acres.com/bbs/thread-405991-1-1.html

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明

custom counter

GMT+8, 2018-5-27 00:16

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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