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

3.7 Facebook Onsite

 
🔗
bobzhang2004 2016-4-3 11:52:44 | 只看该作者
全局:
赞分享和详细的讲解!
回复

使用道具 举报

🔗
sealove999 2016-4-4 04:08:22 | 只看该作者
全局:
lotustree86 发表于 2016-3-10 18:02
1. Singly, ListNode convertBT(TreeNode node);

我觉得你问得几个问题都非常好。我跟面试官的交流过 ...

楼主好棒
回复

使用道具 举报

全局:
赞楼主 我让同学内推 都说不招人了(new grad 呜呜
回复

使用道具 举报

🔗
yaq0925 2016-4-13 04:42:05 | 只看该作者
全局:
请问楼主facebook culture fit一般会有什么问题,应该怎么答?谢谢
回复

使用道具 举报

🔗
hison7463 2016-4-13 05:06:13 | 只看该作者
全局:
不是说FB onsite每轮硬性要求算法是两题的吗?怎么LZ每轮大概就一题。。。
回复

使用道具 举报

🔗
 楼主| lotustree86 2016-4-14 07:42:51 | 只看该作者
全局:
hison7463 发表于 2016-4-13 05:06
不是说FB onsite每轮硬性要求算法是两题的吗?怎么LZ每轮大概就一题。。。

是两题呀,我有补充!最后一轮第一题前面人出过了,所以给了一题,但是后面有follow up.
回复

使用道具 举报

🔗
beyond 2016-4-16 05:57:09 | 只看该作者
全局:
根据楼主的表现应该肯定能拿到offer了!
回复

使用道具 举报

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

使用道具 举报

🔗
sealove999 2016-4-17 08:21:28 | 只看该作者
全局:
第一轮,
  1. public class Solution {
  2.   ListNode b(TreeNode root, ListNode head) {
  3.     ListNode last = null;
  4.     if (root.left != null)
  5.       last = b(root.left, head);

  6.     ListNode ln = new ListNode(root.val);
  7.     if (last != null)
  8.       last.next = ln;
  9.     else
  10.       head.next = ln;

  11.     if (root.right != null)
  12.       return b(root.right, ln);
  13.     else
  14.       return ln;
  15.   }

  16.   public ListNode convertBT(TreeNode node) {
  17.     if (node == null)
  18.       return null;
  19.     ListNode myhead = new ListNode(-1);
  20.     b(node, myhead);
  21.     return myhead.next;
  22.   }

  23.   public static void main(String[] args) {
  24.     Solution s = new Solution();
  25.     TreeNode tn1 = new TreeNode(1);
  26.     TreeNode tn2 = new TreeNode(2);
  27.     TreeNode tn3 = new TreeNode(3);
  28.     TreeNode tn4 = new TreeNode(4);
  29.     TreeNode tn5 = new TreeNode(5);
  30.     TreeNode tn6 = new TreeNode(6);
  31.     TreeNode tn7 = new TreeNode(7);
  32.     tn1.left = tn2;
  33.     tn2.right = tn4;
  34.     tn1.right = tn3;
  35.     tn3.left = tn5;
  36.     tn3.right = tn6;
  37.     tn5.right = tn7;
  38.     for (ListNode ln = s.convertBT(tn1); ln != null; ln = ln.next) {
  39.       System.out.println(ln.val);
  40.     }
  41.   }
  42. }
复制代码
回复

使用道具 举报

🔗
sealove999 2016-4-17 08:21:54 | 只看该作者
全局:
第二轮,第一题
  1. public class Solution {
  2.   public Map<Character, Integer> numberconnectedcolor(char[][] matrix) {
  3.     int[][] dirs = new int[][] {{0, 1}, {1, 0}/* , {0, -1}, {-1, 0} */};
  4.     int root[] = new int[matrix.length * matrix[0].length];
  5.     Arrays.fill(root, -1);
  6.     for (int i = 0; i < matrix.length; i++) {
  7.       for (int j = 0; j < matrix[0].length; j++) {
  8.         for (int[] dir : dirs) {
  9.           int x = i + dir[0];
  10.           int y = j + dir[1];
  11.           if (x >= 0 && x < matrix.length && y >= 0 && y < matrix[0].length
  12.               && matrix[i][j] == matrix[x][y]) { // same color
  13.             int r1 = find(root, x * matrix[0].length + y);
  14.             int r2 = find(root, i * matrix[0].length + j);
  15.             if (r1 != r2) { // union
  16.               root[r2] = r1; // root[r1] = r2;
  17.             }
  18.           }
  19.         }
  20.       }
  21.     }
  22.     Map<Character, Integer> ret = new HashMap<>();
  23.     for (int i = 0; i < matrix.length; i++) {
  24.       for (int j = 0; j < matrix[0].length; j++) {
  25.         if (root[i * matrix[0].length + j] == -1) {
  26.           char color = matrix[i][j];
  27.           if (!ret.containsKey(color)) {
  28.             ret.put(color, 0);
  29.           }
  30.           ret.put(color, ret.get(color) + 1);
  31.         }
  32.       }
  33.     }
  34.     return ret;
  35.   }

  36.   int find(int root[], int idx) {
  37.     while (root[idx] != -1) {
  38.       idx = root[idx];
  39.     }
  40.     return idx;
  41.   }

  42.   public static void main(String[] args) {
  43.     Solution s = new Solution();
  44.     System.out.println(s.numberconnectedcolor(new char[][] {{'a', 'b'}, {'b', 'b'}, {'b', 'a'}}));
  45.   }
  46. }
复制代码
回复

使用道具 举报

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

本版积分规则

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