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

Airbnb Code Challenge 12

全局:

2018(10-12月) 码农类General 硕士 全职@airbnb - 内推 - 在线笔试  | | Other | 应届毕业生
题目截图附在下面👇
[img=110,0]https://www.1point3acres.com/bbs/forum.php
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
rong>补充内容 (2018-11-16 15:28):
我把代码贴在下面的回复里

本帖子中包含更多资源

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

x

评分

参与人数 10大米 +40 收起 理由
wxgymsfd + 3 给你点个赞!
lwygoubi + 3 给你点个赞!
xiaoxuesheng123 + 3 很有用的信息!
鱼淼淼 + 3 给你点个赞!
64203221 + 3 很有用的信息!

查看全部评分


上一篇:Twitter OA
下一篇:FB intern电面
 楼主| lc3397 2018-11-16 15:29:35 | 只看该作者
全局:
Java代码:
  1. // 千万不要抄啊
  2.     static class DataEntry{
  3.         int index;
  4.         int floorVal;
  5.         double diff;
  6.         public DataEntry(int index, int floorVal, double differenceFromFloor){
  7.             this.index = index;
  8.             this.floorVal = floorVal;
  9.             this.diff = differenceFromFloor;
  10.         }
  11.     }

  12.     public static List<Integer> Solution5(List<Double> prices, int target){
  13.         DataEntry[] entries = new DataEntry[prices.size()];
  14.         int floorSum = 0, xFloor;
  15.         double x;
  16.         for(int i=0; i<prices.size(); i++){
  17.             x = prices.get(i);
  18.             xFloor = (int)x;
  19.             floorSum += xFloor;
  20.             DataEntry newDataEntry = new DataEntry(i, xFloor, x - xFloor);
  21.             entries[i] = newDataEntry;
  22.         }

  23.         int totalDiff = target - floorSum;
  24.         Arrays.sort(entries, (a, b) -> a.diff >= b.diff ? -1 : 1); // sort entries according to difference

  25.         int idx = 0;
  26.         while(idx < totalDiff){
  27.             entries[idx] = new DataEntry(entries[idx].index, entries[idx].floorVal+1, entries[idx].diff); // add 1 to the first diff entries
  28.             idx++;
  29.         }

  30.         Arrays.sort(entries, (a, b) -> a.index < b.index ? -1 : 1); // sort entries according to original idx

  31.         List<Integer> result = new ArrayList();
  32.         for(int i=0; i<prices.size(); i++){
  33.             result.add(entries[i].floorVal);
  34.         }
  35.         return result;
  36.     }
复制代码


测试:
  1. public static void main(String[] args) {
  2.         double[] arr = { 1.2, 3.7, 2.3, 4.8, 5.0, 6.7}; // fine
  3.         List<Double> prices = Arrays.stream(arr).boxed().collect(Collectors.toList());
  4.         int target = 24;

  5.         List<Integer> res = Solution5(prices, target);
  6.         for(int i: res)
  7.             System.out.print(i + " ");
  8.     }
复制代码

补充内容 (2018-11-16 15:57):
选择语言是Java 8
回复

使用道具 举报

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

使用道具 举报

🔗
yeou110 2018-11-16 03:41:50 | 只看该作者
全局:
跪谢,给你赞
回复

使用道具 举报

🔗
kensington 2018-11-16 04:33:25 | 只看该作者
全局:
没讨论solution哈,气床的题都是背景很多吗
回复

使用道具 举报

🔗
 楼主| lc3397 2018-11-16 14:23:15 | 只看该作者
全局:

谢谢加米
回复

使用道具 举报

🔗
 楼主| lc3397 2018-11-16 15:32:02 | 只看该作者
全局:
kensington 发表于 2018-11-16 04:33
没讨论solution哈,气床的题都是背景很多吗

回复在上面了
回复

使用道具 举报

全局:
楼主收到回复了吗~
回复

使用道具 举报

🔗
 楼主| lc3397 2018-11-27 04:36:46 | 只看该作者
全局:

收到啦 准备两轮电面
回复

使用道具 举报

🔗
鱼淼淼 2018-11-29 11:02:42 | 只看该作者
全局:
问下challenge12就是固定的题吗?
回复

使用道具 举报

🔗
 楼主| lc3397 2018-11-29 11:22:24 | 只看该作者
全局:
鱼淼淼 发表于 2018-11-29 11:02
问下challenge12就是固定的题吗?

应该是吧,但是我看之前的几个帖子有一些区别:比如输入和输出的要求,有的写的是array有的写的是list. 还有一些对输出顺序没有要求。但是总体题目是一个意思。
回复

使用道具 举报

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

本版积分规则

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