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

LinkedIn senior 电面

全局:

2016(4-6月) 码农类General 硕士 全职@linkedin - 内推 - 技术电面  | | Other | 在职跳槽

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

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

x
LinkedIn 现在码农只招senior的了

电面第一题实现pow(a,b)
第二题tree level traversal, follow up 是带间距的输出
/**
*
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
     1
*        3   5
*      2   4   7
*    9   6   8


上一篇:Yelp OA V4
下一篇:收到 uber recruiter的email说的约个时间discuss一下,这个算是第一轮店面吗
推荐
xiaotdl 2018-3-9 16:18:44 | 只看该作者
全局:
思路跟把整个binary tree inorder存到array里很像。
先dfs求树的高度h。
然后把每层都存到大小为2^h - 1的array里,逐层打出来就好了。
  1. class Solution {
  2. /**
  3. * Sample input:
  4. *
  5. *          1
  6. *         / \
  7. *        2   3
  8. *       / \  / \
  9. *      4   5 6  7
  10. *
  11. * Expected output:
  12. *    1
  13. *    2 3
  14. *    4 5 6 7
  15. *
  16. * Follow up expected output:
  17. *      1   
  18. *   2    3
  19. * 4  5 6 7
  20. **/
  21.     public void levelOrderPrint(TreeNode root) {
  22.         int h = dfs(root);
  23.         int totalNodes = (1 << h) - 1;

  24.         Map<TreeNode, int[]> m = new HashMap<>(); // node2(l,r)

  25.         Queue<TreeNode> q = new LinkedList<>();
  26.         q.offer(root);
  27.         m.put(root, new int[]{0, totalNodes - 1});
  28.         int currH = h;
  29.         while (!q.isEmpty()) {
  30.             int size = q.size();
  31.             int[] lvl = new int[totalNodes];
  32.             for (int i = 0; i < size; i++) {
  33.                 TreeNode curr = q.poll();
  34.                 int currPos = (m.get(curr)[1] + m.get(curr)[0]) / 2;
  35.                 lvl[currPos] = curr.val;
  36.                 if (curr.left != null) {
  37.                     q.offer(curr.left);
  38.                     m.put(curr.left, new int[]{m.get(curr)[0], currPos - 1});
  39.                 }
  40.                 if (curr.right != null) {
  41.                     q.offer(curr.right);
  42.                     m.put(curr.right, new int[]{currPos + 1, m.get(curr)[1]});
  43.                 }
  44.             }
  45.             currH--;
  46.             for (int i = 0; i < lvl.length; i++) {
  47.                 System.out.print(lvl[i] != 0 ? lvl[i] : " ");
  48.             }
  49.             System.out.println();
  50.         }
  51.     }

  52.     private int dfs(TreeNode root) {
  53.         if (root == null) return 0;
  54.         return Math.max(dfs(root.left), dfs(root.right)) + 1;
  55.     }

  56.     public static void main(String[] args) {
  57.         TreeNode _1 = new TreeNode(1);
  58.         TreeNode _2 = new TreeNode(2);
  59.         TreeNode _3 = new TreeNode(3);
  60.         _1.left = _2;
  61.         _1.right = _3;
  62.         TreeNode _4 = new TreeNode(4);
  63.         TreeNode _5 = new TreeNode(5);
  64.         _2.left = _4;
  65.         _2.right = _5;
  66.         TreeNode _6 = new TreeNode(6);
  67.         TreeNode _7 = new TreeNode(7);
  68.         _3.left = _6;
  69.         _3.right = _7;
  70.         new Solution().levelOrderPrint(_1);
  71.     }

  72. }
复制代码
回复

使用道具 举报

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

使用道具 举报

🔗
wtcupup 2016-5-14 23:22:22 | 只看该作者
全局:
follow up  啥思路呢
回复

使用道具 举报

🔗
adiggo 2016-5-15 01:24:56 | 只看该作者
全局:
follow up可以用vertical traversal 来解决 楼主怎么做的
回复

使用道具 举报

🔗
vivaroma 2016-5-15 04:02:09 | 只看该作者
全局:
为啥只要senior
回复

使用道具 举报

🔗
laonong15 2016-5-15 10:52:12 | 只看该作者
全局:
我的思路:
1 求出树的高度 h 用一个2的h次方的数组存取每一层的结果
2。第一层的存取位置 curpos = 2 的 h-1次方
3, 接下来循环每一层  如果 node.left != null  pos =   curpos /2
     node.right !=null  pos =  curpos+ curpos/2;

回复

使用道具 举报

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

使用道具 举报

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

使用道具 举报

无效楼层,该帖已经被删除
🔗
wzrthhj 2016-5-19 04:51:01 | 只看该作者
全局:
求出共有几层,比如N层,打印的时候,每层依次空N个格,N-1个格,N-2, N-3.。。。。。。
回复

使用道具 举报

🔗
wzrthhj 2016-5-19 04:52:04 | 只看该作者
全局:
我想问你pass了吗?
回复

使用道具 举报

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

本版积分规则

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