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

Google New Grad Phone Interview

全局:

2014(10-12月) 码农类General 硕士 全职@google - 内推 - 技术电面  | | Pass |

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

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

x
一听到熟悉的国人口音一下子放松了 人nice题也简单

0.自我介绍


1. 求tree height

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

5. Resume

G家HR态度好效率高内推一周给电面 面完第二天给onsite

评分

参与人数 2大米 +59 收起 理由
pengzewen37 + 15 感谢分享!
yanyanlr + 44

查看全部评分


上一篇:Google电面通知??
下一篇:Amazon onsite 12/03 新鲜面经
全局:
写了下代码,应该最浅node应该用bfs会好些
  1. public class TreeQuestions {
  2.        
  3.         class Node {
  4.                 int val;
  5.                 Node left;
  6.                 Node right;
  7.         }
  8.        
  9.         public int getTreeHeight(Node root) {
  10.                 if (root == null) {
  11.                         return 0;
  12.                 }
  13.                
  14.                 return Math.max(getTreeHeight(root.left), getTreeHeight(root.right)) + 1;
  15.         }
  16.        
  17.        
  18.         private Node res = null;
  19.         private int level = 0;
  20.         public Node getDeepestLeafNode(Node root) {
  21.                 if (root == null) {
  22.                         return null;
  23.                 }
  24.                 helper(root, 1);
  25.                 return res;
  26.         }
  27.        
  28.         public void helper(Node root, int n) {
  29.                 if (root == null) {
  30.                         return;
  31.                 }
  32.                 if (root.left == null && root.right == null && n > level) {
  33.                         level = n;
  34.                         res = root;
  35.                 }
  36.                 helper(root.left, n + 1);
  37.                 helper(root.right, n + 1);
  38.         }
  39.        
  40.         private Node res2 = null;
  41.         private int level2 = Integer.MAX_VALUE;
  42.         public Node getShallowestLeafNode2(Node root) {
  43.                 if (root == null) {
  44.                         return null;
  45.                 }
  46.                 helper2(root, 1);
  47.                 return res2;
  48.         }
  49.        
  50.         public void helper2(Node root, int n) {
  51.                 if (root == null || n >= level2) {
  52.                         return;
  53.                 }
  54.                 if (root.left == null && root.right == null && n < level2) {
  55.                         level2 = n;
  56.                         res2 = root;
  57.                 }
  58.                 helper(root.left, n + 1);
  59.                 helper(root.right, n + 1);
  60.         }
  61. }
复制代码
回复

使用道具 举报

全局:
第四题,zigzag 打印

  1. public class ZigzagPrintMatrix {

  2.     public static List<Integer> zigzagPrint(int[][] board) {
  3.         List<Integer> result = new ArrayList<Integer>();
  4.         int m = board.length;
  5.         if (m == 0 || board[0].length == 0) return result;
  6.         int n = board[0].length;
  7.         int i = 0, j = 0;
  8.         while (i < m && j < n) {
  9.             result.add(board[i][j]);
  10.             if (i + 1 < m) i++;
  11.             else if (j + 1 < n) j++;
  12.             else break;
  13.             while (i > 0 && j + 1 < n) {
  14.                 result.add(board[i][j]);
  15.                 i--;
  16.                 j++;
  17.             }
  18.             result.add(board[i][j]);
  19.             if (i == 0) j++;
  20.             else i++;
  21.             while (i + 1 < m && j > 0) {
  22.                 result.add(board[i][j]);
  23.                 i++;
  24.                 j--;
  25.             }
  26.         }
  27.         return result;
  28.     }
  29.    
  30.     public static void main(String[] args) {
  31.      //  int[][] board = {{1,2,3,4,5}, {6,7,8,9,1}, {2,3,4,5,6}};
  32.         int[][] board = {{1,2,3}, {4,5,6}, {7,8,9}};
  33.         List<Integer> result = zigzagPrint(board);
  34.         for (int d : result){
  35.             System.out.print(d + " ");
  36.         }
  37.         System.out.println();
  38.     }
  39. }
复制代码
回复

使用道具 举报

推荐
e6175423 2015-12-27 18:10:17 | 只看该作者
全局:
void zigzagPrint(vector<vector<char> > matrix) {
  int n =  matrix.size();
  for(int i = 0; i < 2*n-1; i++) {
    for(int j = 0; j <= min(i,n-1); j++) {
      if (i-j<0 || i-j>=n) {
        continue;
      }
      if (i%2) {
        cout<<matrix[j][i-j];
      } else {
        cout<<matrix[i-j][j];
      }
    }
  }
  cout<<endl;
}

int main() {
  vector<vector<char>> matrix({{'a','b','c'},{'d','e','f'},{'g','h','i'}});
  zigzagPrint(matrix);
}
回复

使用道具 举报

🔗
suonan 2014-12-4 09:05:24 | 只看该作者
全局:
楼主大牛啊,电面问了这么多题! 祝onsite顺利~~
回复

使用道具 举报

🔗
teedoo 2014-12-4 09:40:45 | 只看该作者
全局:
请问楼主zigzag那道题用了extra memory了吗
回复

使用道具 举报

🔗
 楼主| tenliu 2014-12-5 06:48:43 | 只看该作者
全局:
teedoo 发表于 2014-12-4 09:40
请问楼主zigzag那道题用了extra memory了吗

没阿 就暴力解 先下1 再右上直到顶(上或右) 再右1 再左下直到底(左或下) 再考虑下corner case就好
回复

使用道具 举报

🔗
averillzheng 2014-12-28 00:02:31 | 只看该作者
全局:
google的phone面确实简单。
onsite比较难。

有钱就是任性。
回复

使用道具 举报

🔗
yzl232 2014-12-28 00:41:34 | 只看该作者
全局:
国人并没有出leetcode题放水。
都是灵活的题目。
还是楼主实力强
回复

使用道具 举报

🔗
applepie11 2014-12-28 01:20:39 | 只看该作者
全局:
第一题跟第二题有啥区别?? 基本都leetcode吧。。
回复

使用道具 举报

🔗
somethingme 2014-12-29 03:22:04 | 只看该作者
全局:
lz怎么能答了这么多题。。。

我45min一共就一题,做完以后面试官稍微改了改变得比较复杂,就让我说说思路就没再继续了。。。

求攒人品!
回复

使用道具 举报

🔗
ekco 2015-1-2 11:42:06 | 只看该作者
全局:
lz真的是好多题啊
回复

使用道具 举报

🔗
legendava 2015-1-6 13:44:40 | 只看该作者
全局:
为什么那个zigzag a 之后是d,应该是b比较合理感觉
回复

使用道具 举报

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

本版积分规则

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