查看: 3663| 回复: 9
跳转到指定楼层
上一主题 下一主题
收起左侧

[找工就业] AirBnb面经【挂了】

全局:

2022(4-6月)-CS本科+3-5年 | Other| 码农类General全职@airbnb

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

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

x
楼主,最近面了下airbnb
第一题:

You need to implement a simplified `tree` command line tool.-baidu 1point3acres
1. You will get some paths like '/aaa/bcd/c.txt' which split by '/' and consisted with several characters, every path starts with '/'
2. All the characters are in `[a-zA-Z0-9./]`
3. You need to output files/sub-folders in the same folder in dictionary order
4. You need to output the hierarchical path tree as following:
sample input:
.google  и
[
"/bin/usr/bash",
"/var/test/.ssh",
"/var/log/wifi.log",
"/opt",
"/xyz"
]

sample output:

+-- bin
|   +-- usr-baidu 1point3acres
|       +-- bash
+-- opt
+-- var. ----
|   +-- log
|   |   +-- wifi.log
|   +-- test
|       +-- .ssh
+-- xyz

the indent should be 4 blanks
* new node starts with `+-- `
* the siblings are linked by '|'
Note: How to handle the input/output is not important. You can even hard code the input as a string array in the code.

我的代码:

  1. import java.util.*;

  2. public class Main {
  3.     public static class Tree {
  4.         String val;

  5.         Tree() {
  6.         };

  7.         Tree(String val) {
  8.             this.val = val;
  9.         }

  10.         ArrayList<Tree> children = new ArrayList<>();
  11.     }
  12. .--
  13.     public static void main(String[] args) {
  14. . ----

  15.         String[] arr = {"/bin/usr/bash",. 1point3acres.com
  16.                 "/var/test/.ssh",. 1point 3 acres
  17.                 "/var/log/wifi.log",
  18.                 "/opt",. .и
  19.                 "/xyz"
  20.                         };
  21.         Arrays.sort(arr);
  22.         Tree head = new Tree("/");
  23.         Tree t = head;
  24.         for (String s : arr) {
  25.             String[] tmp = s.split("\\/");
  26.             t = head;. From 1point 3acres bbs
  27.             for (String a : tmp) {.google  и
  28.                 if (a.equals("")) {
  29.                     continue;
  30.                 }
  31.                 boolean flag = false;
  32.                 for (Tree tree : t.children
  33.                 ) {
  34.                     if (a.equals(tree.val)) {
  35.                         t = tree;. .и
  36.                         flag = true;. Χ
  37.                         break;
  38.                     }
  39.                 }
  40.                 if (!flag) {
  41.                     Tree tree = new Tree(a);
  42.                     t.children.add(tree);
  43.                     t = tree;
  44.                 }
  45.             }
  46.         }
  47.         //. From 1point 3acres bbs
  48. -baidu 1point3acres
  49.         dfs(head, 0, "",false);

  50.       //  System.out.println("1234");
  51.         return;
    . Waral dи,

  52.     }

  53.     public static void dfs(Tree t, int i, String s,Boolean hasFloor) {
  54.         System.out.println(s + t.val);
  55.         if (t.children.isEmpty()) {
  56.             return;
  57.         }

  58.         int num = t.children.size();.1point3acres
  59.         for (int j = 0; j < num; ++j) {
  60.             Tree tree = t.children.get(j);
  61.             StringBuffer sb = new StringBuffer(s);
  62.             if ( i == 0){
  63.                 sb.append("+-- ");
    . From 1point 3acres bbs
  64.             }
  65.             if (i > 0 ) {
  66.                 if (hasFloor) {
  67.                     sb.insert(sb.length() - 4, "|   ");
  68.                 } else {
  69.                     sb.insert(sb.length() - 4, "    ");
  70.                 }
  71.             }
  72.             if(j == num-1) {. 1point3acres
  73.                 hasFloor = false;
  74.             }else {
  75.                 hasFloor = true;
  76.             }
  77.             dfs(tree, i + 1, sb.toString(),hasFloor);
  78.         }

  79.     }. 1point 3acres

  80. }
复制代码
第二题:. From 1point 3acres bbs
Problem statement
Given a nonnegative number set (can have duplicates), divide it into two sets so that the sum of the variances of these two sets is minimized. You can shuffle set order. The values of two sets cannot overlap. All number in the original set must appear in one of the two sets.
Finally return the value of the sum. The result include one decimal place.
The definition of variance: S^2= ∑ (X-a) ^2 / (n-1), where X is the average, a is every number in the set, and n is the size of the set.. From 1point 3acres bbs
For example: There is a set [1,3,1] . We can divide it into [1,1] and [3], Then return the result:0.0
Please simply proof the correctness of your solution.
Follow up: What if we want to divide the set into three subsets?
  1. //CASE 1:
  2. // Input
  3. // [4,3,2,1]
  4. // Output
  5. // 1.0
  6. import java.util.*;
  7. public class Main {
  8.     public static void main(String[] args) {
  9.         //Scanner in = new Scanner(System.in);
  10.         //int a = in.nextInt();.
  11.         //System.out.println(a);
  12.         System.out.println("Hello World!");. 1point 3acres
  13.         
  14.         // n 知道 sum 知道 min ((sumA/a -ai)/a-1 + ((sum-aumA)/n-a - bi)/n-a-1)
  15.         // sum 可以分成 a+b个数  (sumA/a-ai)^2/ a-1 + sumB/b
  16.         int []arr = {4,3,2,1};
  17.         //int[]arr = {1,3,1};. 1point 3acres
  18.         Arrays.sort(arr);
  19.         int len = arr.length; // 数组长度
  20.         // 如果数组小于 2 则直接返回 0
  21.         if( len  < 2 ) { ..
  22.             System.out.println(0);
  23.             return ;
  24.         }
  25.         int sum = 0; // 前缀求和
  26.         double ans = 10000;  // 存储最小的结果.--
  27.         int sum2 = 0;
  28.         for( int i = 0; i < len; ++i ) {
  29.             sum += arr[i];
  30.             sum2 += arr[i]*arr[i];
  31.         }. Waral dи,
  32.         // 选择分割点
  33.         int pre = 0; //前缀和. check 1point3acres for more.
  34.         int pre2 = 0; // 前缀平方和
  35.         for ( int i = 0; i < len-1; ++i ) {
    . From 1point 3acres bbs
  36.             pre += arr[i];
  37.             pre2 += arr[i]*arr[i];
  38.             int ave = pre/(i+1);
  39.             int x =(i+1)*ave*ave;
  40.             int mid = 2*ave*pre;
  41.             int y = pre2;
  42.                 // 长度为0 则直接为0
  43.             double a = 0;
  44.             double b = 0;
  45.             if(i > 0) {
  46.               a = (double)(x-mid+y)/i;   
  47.            }else{. .и
  48.              a = 0;
  49.            }
  50.             //System.out.println("a:"+a);
  51.             int ave2 = (sum-pre)/(len-i-1);
  52.            // System.out.println("ave2:"+ave2);. Waral dи,
  53.             int x2 = (len-i-1)*ave2*ave2;
  54.             //System.out.println("x2:"+x2);
  55.             int mid2 = 2*ave2*(sum-pre);
  56.             //System.out.println("mid2:"+mid2);
  57.             int y2 = sum2-pre2;
  58.             //System.out.println("y2:"+y2);. 1point 3acres
  59.                 if(len-i-1>1) {
  60.                     b = (double)(x2-mid2+y2)/(len-i-1-1);
  61.                 }else{
  62.                     b = 0;
  63.                 }
  64.             //System.out.println("b:"+b);
  65.             ans= Math.min(a+b,ans);
  66.             
  67.         }
  68.         System.out.println(ans);
  69.         
  70.     }
  71.    
  72.   . check 1point3acres for more.
  73. }
复制代码
第二题面试的时候有个变量ave2没有写2 导致答案一直不对,时间来不及 面试官就说到这吧。。自己太菜了 虽然挂了 求点大米安慰下~~

评分

参与人数 2大米 +4 收起 理由
mikemike0 + 3 很有用的信息!
Felix1218 + 1 赞一个

查看全部评分


上一篇:2022年还有什么好去处(跳槽公司选择)
下一篇:微软两个组offer能相互match吗?
推荐
jeanne_17 2022-5-4 03:02:23 | 只看该作者
全局:
skyshuaiboy 发表于 2022-5-2 02:01
|这个符号 你可以理解为 关联同级目录的  因为.ssh的上一级目录没有同级目录了 所以不需要加 |

还是不理解  .ssh 上级是/test/么, /test/不是有同级目录 /log/么 而且log字典顺序再test前面
回复

使用道具 举报

推荐
 楼主| skyshuaiboy 2022-4-30 18:09:45 | 只看该作者
全局:
Felix1218 发表于 2022-4-27 00:07
已加米 请问楼主怎么获得Airbnb面试机会呢 谢谢

投简历 然后oa做题 过了就可以面试了
回复

使用道具 举报

🔗
einApfel 2022-4-26 23:52:22 | 只看该作者
全局:
楼主这是电面吗?
回复

使用道具 举报

全局:
已加米 请问楼主怎么获得Airbnb面试机会呢 谢谢
回复

使用道具 举报

🔗
 楼主| skyshuaiboy 2022-4-30 18:11:00 | 只看该作者
全局:
einApfel 发表于 2022-4-26 23:52
楼主这是电面吗?

算ov吧 你说的是电面是OA么?就是做题?
回复

使用道具 举报

🔗
jeanne_17 2022-5-2 08:25:47 | 只看该作者
全局:
为什么 同为 第三级directory    |       +-- .ssh 和   |       +-- bash 只有一个  |   . .и
而 |   |   +-- wifi.log 这个有两个|
回复

使用道具 举报

🔗
 楼主| skyshuaiboy 2022-5-2 17:01:53 | 只看该作者
全局:
jeanne_17 发表于 2022-5-2 08:25
为什么 同为 第三级directory    |       +-- .ssh 和   |       ...

|这个符号 你可以理解为 关联同级目录的  因为.ssh的上一级目录没有同级目录了 所以不需要加 |
回复

使用道具 举报

🔗
mikemike0 2022-5-3 16:23:34 | 只看该作者
全局:
感謝分享
這是onsite嗎?
回复

使用道具 举报

🔗
 楼主| skyshuaiboy 2022-5-4 16:18:24 | 只看该作者
全局:
mikemike0 发表于 2022-5-3 16:23
感謝分享.
這是onsite嗎?

嗯 是的 感谢加米~
回复

使用道具 举报

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

本版积分规则

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