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

Google暑期实习电面

全局:

2016(7-9月) 码农类General 硕士 实习@google - 校园招聘会 - 技术电面  | | Other | 应届毕业生

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

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

x
两轮紧靠着的电面,都是直接上来就问问题,简历一句话都没问,现在招实习都那么直接吗

第一轮是中国小哥,问题是 给定一个9位的键盘,

1 2 3
4
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
是很难,只是我太菜, 当为接下来其他面试攒经验和rp吧~

评分

参与人数 2大米 +40 收起 理由
whdawn + 30
clfhaha1234 + 10 感谢分享!

查看全部评分


上一篇:google水面
下一篇:Amazon OA2 10.27due
推荐
echo33 2015-12-13 03:14:25 | 只看该作者
全局:
第一题是分成[1,3,7,9], [2,4,6,8],[5]三种键吗

ls的好像不太对,即使你加上visited

得给每个数字加个obstacle 比如1:[2:3,4:7,5:9] 如果prefix里已经有某个数字e.g.2就可以连对应的那个数字 e.g.3了
回复

使用道具 举报

推荐
singku 2016-1-7 05:27:43 | 只看该作者
全局:
第一题
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string>
  4. #include <iostream>

  5. #define N   (3)

  6. using namespace std;

  7. int visited[N*N] = {0};

  8. bool can_visit(int i, int j) {

  9.     if (i == j) {
  10.         return false;
  11.     } else if (visited[j-1]) {
  12.         return false;
  13.     }

  14.     //start point
  15.     if (i == 0) {
  16.         return true;
  17.     }

  18.     int rowi = (i-1) / N + 1;
  19.     int coli = (i-1) % N + 1;
  20.     int rowj = (j-1) / N + 1;
  21.     int colj = (j-1) % N + 1;

  22.     if (rowi == rowj) {
  23.         int diff = coli - colj;
  24.         if (diff == 1 || diff == -1) {
  25.             return true;
  26.         } else {
  27.             int k;
  28.             int min = coli > colj ?colj :coli;
  29.             int max = coli > colj ?coli :colj;
  30.             for (k = min+1; k < max; k++) {
  31.                 if (!visited[(rowi-1) * N + k - 1]) {
  32.                     return false;
  33.                 }
  34.             }
  35.             return true;
  36.         }
  37.     } else if (coli == colj) {
  38.         int diff = rowi - rowj;
  39.         if (diff == 1 || diff == -1) {
  40.             return true;
  41.         } else {
  42.             int k;
  43.             int min = rowi > rowj ?rowj :rowi;
  44.             int max = rowi > rowj ?rowi :rowj;
  45.             for (k = min+1; k < max; k++) {
  46.                 if (!visited[(k-1) * N + coli - 1]) {
  47.                     return false;
  48.                 }
  49.             }
  50.             return true;
  51.         }
  52.     } else {
  53.         int diffcol = coli - colj;
  54.         int diffrow = rowi - rowj;
  55.         if (diffcol == diffrow || diffcol == -diffrow) {//diagnal line
  56.             if (diffcol == 1 || diffcol == -1) {//ajacent
  57.                 return true;
  58.             }
  59.             int minrow = rowi > rowj ?rowj :rowi;
  60.             int maxrow;
  61.             int startcol;
  62.             int r;
  63.             if (rowi == minrow) {
  64.                 startcol = coli;
  65.                 maxrow = rowj;
  66.                 if (coli < colj) {
  67.                     r = 1;
  68.                 } else {
  69.                     r = -1;
  70.                 }
  71.             } else {
  72.                 startcol = colj;
  73.                 maxrow = rowi;
  74.                 if (coli < colj) {
  75.                     r = -1;
  76.                 } else {
  77.                     r = 1;
  78.                 }
  79.             }
  80.             int k;
  81.             for (k = minrow+1; k < maxrow; k++) {
  82.                 if (!visited[(k-1)*N + startcol + r * (k-minrow)]) {
  83.                     return false;
  84.                 }
  85.             }
  86.             return true;
  87.         } else {
  88.             return true;
  89.         }
  90.     }
  91. }

  92. string int_to_string(int i) {
  93.     char buf[1024];
  94.     snprintf(buf, sizeof(buf), "%d", i);
  95.     return string(buf);
  96. }

  97. void back_track_visit(int len, int cur_len, int cur_pos, string path, int &total)
  98. {
  99.     if (cur_len == len) {
  100.         total++;
  101.         //cout << path << endl;
  102.         return;
  103.     }

  104.     for (int i = 1; i <= N*N; i++) {
  105.         if (!can_visit(cur_pos, i)) {
  106.             continue;
  107.         }

  108.         visited[i-1] = 1;
  109.         back_track_visit(len, cur_len+1, i, path + ">" + int_to_string(i), total);
  110.         visited[i-1] = 0;
  111.     }
  112. }

  113. int main(void)
  114. {
  115.     int total = 0;
  116.     back_track_visit(9, 0, 0, "", total);
  117.     cout << total << endl;
  118. }
复制代码
回复

使用道具 举报

推荐
aiweiwei 2015-12-12 00:14:27 | 只看该作者
全局:
第一题感觉要处理特殊情况,基本每个数字都要处理一下,类似如下的感觉
if pre == '1':
                if 2 in visited and curr == 3:
                    continue
                if 4 in visited and curr == 7:
                    continue
                if 5 in visited and curr == 9:
                    continue
            if pre == '2':
                if 5 in visited and curr == 8:
                    continue                    
            if pre == '3':
                if 2 in visited and curr == 1:
                    continue
                if 5 in visited and curr == 7:
                    continue
                if 6 in visited and curr == 9:
                    continue                    
            if pre == '4':
                if 5 in visited and curr == 6:
                    continue              
            if pre == '6':
                if 5 in visited and curr == 4:
                    continue                 
            if pre == '7':
                if 8 in visited and curr == 9:
                    continue
                if 4 in visited and curr == 1:
                    continue
                if 5 in visited and curr == 3:
                    continue               
            if pre == '8':
                if 8 in visited and curr == 2:
                    continue               
            if pre == '9':
                if 8 in visited and curr == 7:
                    continue
                if 6 in visited and curr == 3:
                    continue
                if 5 in visited and curr == 1:
                    continue           

第一题写了60行了,感觉挺麻烦的
回复

使用道具 举报

🔗
wbsnt 2015-10-24 09:16:50 | 只看该作者
全局:
为什么说自己菜,有结果了么
回复

使用道具 举报

🔗
kyle3782 2015-10-24 09:57:45 | 只看该作者
全局:
谢谢楼主分享!
回复

使用道具 举报

🔗
xin_gator 2015-10-27 09:15:12 | 只看该作者
全局:
谢谢分享~祝你好运呀!!加油!
回复

使用道具 举报

🔗
nuanuan1208 2015-10-27 23:19:13 | 只看该作者
全局:
请教下楼长第一轮那题是只需要count,还是print out all unique path?除了DFS有什么好方法吗?
回复

使用道具 举报

🔗
翔在天空 2015-10-30 13:14:37 | 只看该作者
全局:
请问第一题什么意思,不太懂
回复

使用道具 举报

🔗
Augustus 2015-11-16 08:30:31 | 只看该作者
全局:
第一题啥意思?能具体讲下马,看不懂。。。
回复

使用道具 举报

🔗
bobzhang2004 2015-12-7 08:41:02 | 只看该作者
全局:
写了下第一题,不太确定是不是正解,欢迎指教
  1. public class KeyboardUniquePath {

  2.         private int count = 0;
  3.         public int getNumberOfKeyboardUniquePath(int n) {
  4.                 if (n <= 0) {
  5.                         return 0;
  6.                 }
  7.                 String[] map = {"24568", "1345679", "24567", "1235789", "12346789", "12356789", "24568", "1345679", "24568"};
  8.                 helper(map, new StringBuilder(), n, "123456789");
  9.                 return count;
  10.         }
  11.         private void helper(String[] map, StringBuilder sb, int n, String choices) {
  12.                 if (sb.length() == n) {
  13.                         count++;
  14.                         return;
  15.                 }
  16.                 for (int i = 0; i < choices.length(); i++) {
  17.                         char c = choices.charAt(i);
  18.                         sb.append(c);
  19.                         helper(map, sb, n, map[(int)(c - '1')]);
  20.                         sb.deleteCharAt(sb.length() - 1);
  21.                 }
  22.         }
  23.        
  24.         public static void main(String[] args) {
  25.                 KeyboardUniquePath su = new KeyboardUniquePath();
  26.                 System.out.println(su.getNumberOfKeyboardUniquePath(1));
  27.         }
  28. }
复制代码

补充内容 (2015-12-7 23:16):
如果不能有重复数字的话,加一个if (sb.toString().contains(String.valueOf(c))) continue;就行了,因为最多9个数字,所以这儿也是contant的时间
回复

使用道具 举报

🔗
bobzhang2004 2015-12-7 08:42:29 | 只看该作者
全局:
请问楼主这个求问最长的合法的英语词汇是怎么做的?
回复

使用道具 举报

🔗
jefferyy 2015-12-7 12:56:29 | 只看该作者
全局:
bobzhang2004 发表于 2015-12-7 08:41
写了下第一题,不太确定是不是正解,欢迎指教

这个貌似没有处理一个键只能用一次
应该加一个 visited hashset, 如果已经出现 跳过
回复

使用道具 举报

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

本版积分规则

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