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

朋友的G家onsite面經

全局:

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

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

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

x
1. A tree node has K children, noted as K-way tree. Each child either has a integer value or is NULL. Write a function to recursively rearrange this tree so that all the children that are not NULL are moved to the left most. All the NULL children are moved to the right. The relative sequence of the non-NULL children should stay the same after your function call.

2.1 Given a binary search tree, where each node stores an integer value, a lower bound and an upper bound. Cal
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
r different color, only white or black). If the adjacent place is empty and all other adjacent places are either empty or placed by a different color stone, that is a liberty.

求大米~~~

上一篇:google电面 第一次遇见这么好的面试官
下一篇:BB phone 11月

本帖被以下淘专辑推荐:

推荐
Longfeng 2016-12-29 15:56:37 | 只看该作者
全局:
请问楼主在哪栋楼面的?
回复

使用道具 举报

推荐
工图新一 2016-12-18 07:42:13 | 只看该作者
全局:
laiguojiuhao 发表于 2016-12-18 03:12
如果一个子旁边放了相同颜色的子,那么相邻的空白也不算liberty了吗

你是怎么理解这个liberty的?

评分

参与人数 1大米 +10 收起 理由
youhusky + 10 欢迎来一亩三分地论坛!

查看全部评分

回复

使用道具 举报

推荐
工图新一 2016-12-18 02:06:02 | 只看该作者
全局:
第一题:
  1. import java.util.*;

  2. public class Solution {
  3.     private class TreeNode {
  4.         int val;
  5.         List<TreeNode> children;
  6.         public TreeNode(int val) {
  7.             this.val = val;
  8.             this.children = new ArrayList<>();
  9.             for (int index = 0; index < k; index ++) children.add(null);
  10.         }
  11.     }
  12.     public TreeNode rearrange(TreeNode root) {
  13.         if (root == null) return root;
  14.         for (TreeNode child : root.children) {
  15.             rearrange(child);
  16.         }
  17.         int left = 0, right = k - 1;
  18.         while (left < right) {
  19.             while (left < right && root.children.get(left) != null) left ++;
  20.             while (left < right && root.children.get(right) == null) right --;
  21.             if (left < right) {
  22.                 TreeNode tmpNullNode = root.children.get(left);
  23.                 root.children.set(left, root.children.get(right));
  24.                 root.children.set(right, null);
  25.             }
  26.         }
  27.         return root;
  28.     }
  29. }
复制代码
回复

使用道具 举报

🔗
工图新一 2016-12-18 02:10:20 | 只看该作者
全局:
第二题:
  1. import java.util.*;

  2. public Solution {
  3.     private class Node {
  4.         int val;
  5.         Node left, right;
  6.         public Node(int val) {
  7.             this.val = val;
  8.         }
  9.     }
  10.     public int countSum(Node root, int low, int high) {
  11.         if (root == null) return 0;
  12.         if (root.val > high) {
  13.             return countSum(root.left, low, high);
  14.         } else if (root.val < low) {
  15.             return countSum(root.right, low, high);
  16.         } else {
  17.             return countSum(root.left, low, root.val) + root.val + countSum(root.right, root.val, high);
  18.         }
  19.     }
  20. }
复制代码
回复

使用道具 举报

🔗
wsrrzxl 2016-12-18 02:14:48 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
laiguojiuhao 2016-12-18 02:29:54 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
laiguojiuhao 2016-12-18 02:30:19 | 只看该作者
全局:
laiguojiuhao 发表于 2016-12-18 02:29
要stable的,直接交换不行

回错了。。。回的第一题
回复

使用道具 举报

无效楼层,该帖已经被删除
🔗
工图新一 2016-12-18 02:44:07 | 只看该作者
全局:
laiguojiuhao 发表于 2016-12-18 02:29
要stable的,直接交换不行

懂了,所以双指针都应该从left 到 right,不能分布从两边开始
回复

使用道具 举报

🔗
工图新一 2016-12-18 02:45:53 | 只看该作者
全局:
2.3
  1. import java.util.*;
  2. public class Solution {
  3.     public boolean canFormSquare(int[][] points) {
  4.         if (! isInputValid(points)) return false;
  5.         for (int secondIndex = 1; secondIndex < 4; secondIndex ++) {
  6.             int firstLength = countLen(points, 0, secondIndex);
  7.             int[] firstMid = new int[]{points[0][0] + points[secondIndex][0], points[0][1] + points[secondIndex][1]};
  8.             int secondLength = 0;
  9.             int[] secondMid = {};
  10.             switch(secondIndex) {
  11.                 case 1: {
  12.                     secondLength = countLen(points, 2, 3);
  13.                     secondMid = new int[] {points[2][0] + points[3][0], points[2][1] + points[3][1]};
  14.                     break;
  15.                 }
  16.                 case 2: {
  17.                     secondLength = countLen(points, 1, 3);
  18.                     secondMid = new int[] {points[1][0] + points[3][0], points[1][1] + points[3][1]};
  19.                     break;
  20.                 }
  21.                 case 3: {
  22.                     secondLength = countLen(points, 1, 2);
  23.                     secondMid = new int[] {points[1][0] + points[2][0], points[1][1] + points[2][1]};
  24.                     break;
  25.                 }
  26.             }
  27.             if (secondLength == firstLength && firstMid[0] == secondMid[0] && firstMid[1] == secondMid[1]) return true;
  28.         }
  29.         return false;
  30.     }
  31.     private boolean isInputValid(int[][] points) {
  32.         for (int firstIndex = 0; firstIndex < 3; firstIndex ++) {
  33.             for (int secondIndex = firstIndex + 1; secondIndex < 4; secondIndex ++) {
  34.                 if (points[firstIndex][0] == points[secondIndex][0] && points[firstIndex][1] == points[secondIndex][1]) return false;
  35.             }
  36.         }
  37.         return true;
  38.     }
  39.     private int countLen(int[][] points, int index1, int index2) {
  40.         int[] pointA = points[index1], pointB = points[index2];
  41.         return (int)Math.pow(pointA[0] - pointB[0], 2) + (int)Math.pow(pointA[1] - pointB[1], 2);
  42.     }
  43.     public static void main(String[] args) {
  44.         Solution sol = new Solution();
  45.         int[][] points = {{0,0}, {0, 1}, {1, 0}, {1,1}};
  46.         boolean res = sol.canFormSquare(points);
  47.         System.out.println(res);
  48.     }
  49. }
复制代码
回复

使用道具 举报

🔗
wsrrzxl 2016-12-18 02:55:00 | 只看该作者
全局:

你这个只能判断是长方形吧 并不能判断是正方形
回复

使用道具 举报

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

本版积分规则

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