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

亜麻OA

🔗
匿名用户-6U6O2  2023-8-1 03:08:57 |倒序浏览

2023(7-9月) 码农类General 本科 全职@amazon - 内推 - 在线笔试  | 😐 Neutral 😐 Average | Other | 在职跳槽
题一Bag of Rices, 需用二分搜索否则很多case会超时
题二像是新题
您好!
本帖隐藏的内容需要积分高于 110 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 110 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies

本帖子中包含更多资源

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

x

评分

参与人数 1大米 +12 收起 理由
匿名用户-TUHA2 + 12

查看全部评分


上一篇:Flexport 非典型 Timeline
下一篇:有人面过Balyasny BAM的sde岗位吗?
地里匿名用户
推荐
匿名用户-DNTXA  2023-8-17 09:38:05
在这里提供一个第二题解法,但是直觉告诉我可能不是最优的,因为搜索范围是[-10^9, 10^9],数组长度最大在10^5,感觉这个数量级走两遍binary search还是很容易TLE。抛砖引玉,看看有没有更好的解法

  1. public class Main {
  2.     public static void main(String[] args) {
  3.         List<Integer> center = new ArrayList<>();
  4.         center.add(-2);
  5.         center.add(1);
  6.         center.add(0);
  7.         long d = 8;
  8.         
  9.         System.out.println(numberOfSuitableLocations(center, d));
  10.     }
  11.    
  12.     public static int numberOfSuitableLocations(List<Integer> center, long d) {
  13.         int n = center.size();
  14.         d /= 2;
  15.         
  16.         Collections.sort(center);
  17.         
  18.         long minDistance = 0L;
  19.         for(int i = 0; i < n / 2; i++) {
  20.             minDistance += center.get(n - 1 - i) - center.get(i);
  21.         }
  22.         if(minDistance > d)
  23.             return 0;
  24.         
  25.         int left = searchLeft(center, -1_000_000_000, center.get(n / 2), d);
  26.         int right = searchRight(center, center.get(n / 2), 1_000_000_000, d);
  27.         
  28.         return right - left + 1;
  29.     }
  30.    
  31.     private static int searchLeft(List<Integer> center, int start, int end, long d) {
  32.         while(start < end) {
  33.             int mid = start + (end - start) / 2;
  34.             if(canFulfill(center, mid, d)) {
  35.                 end = mid;
  36.             } else {
  37.                 start = mid + 1;
  38.             }
  39.         }
  40.         return start;
  41.     }
  42.    
  43.     private static int searchRight(List<Integer> center, int start, int end, long d) {
  44.         while(start < end) {
  45.             int mid = start + (end - start + 1) / 2;
  46.             if(canFulfill(center, mid, d)) {
  47.                 start = mid;
  48.             } else {
  49.                 end = mid - 1;
  50.             }
  51.         }
  52.         return start;
  53.     }
  54.    
  55.     private static boolean canFulfill(List<Integer> center, int mid, long d) {
  56.         long distance = 0L;
  57.         for(int c: center) {
  58.             distance += (long)Math.abs(mid - c);
  59.             if(distance > d)
  60.                 return false;
  61.         }
  62.         return true;
  63.     }
  64. }
复制代码
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-6U6O2  2023-8-18 03:28:52
MichelleX 发表于 2023-8-17 06:38
感谢感谢~~我就是对系统设计这块感觉没底,不知道考的啥

会给你一些场景让你做技术选型,你要给不同选项打分(五分制)
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-K2IOC  2023-8-1 22:19:22 来自APP
这是亚麻什么职位的啊感谢
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-6U6O2  2023-8-2 04:07:35
匿名用户 发表于 2023-8-1 07:19
这是亚麻什么职位的啊感谢

SDE2紫薯紫薯
回复

使用道具 举报

全局:
sde 2 是不是现在都内部转岗fill 了
回复

使用道具 举报

🔗
嘟嘟becky 2023-8-3 10:33:20 | 只看该作者
全局:
请问申的是哪个组
回复

使用道具 举报

🔗
Yeeeek 2023-8-11 00:21:52 | 只看该作者
全局:
想问第二题brute force不可以么?就从左边-d/2 到右边+d/2走一遍 看哪些点符合 |x-A| + |x-B| + |x-C| ... <= d/2? 如果是二分的话是怎么个分法呀?
回复

使用道具 举报

🔗
MichelleX 2023-8-17 10:15:01 | 只看该作者
全局:
求问楼主,你的oa有系统设计吗,谢谢!
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-6U6O2  2023-8-17 15:44:14
MichelleX 发表于 2023-8-16 19:15
求问楼主,你的oa有系统设计吗,谢谢!

有的,包含在work simulation部分,不限时,评价方式不详
回复

使用道具 举报

🔗
MichelleX 2023-8-17 21:38:16 | 只看该作者
全局:
匿名用户 发表于 2023-8-17 01:44
有的,包含在work simulation部分,不限时,评价方式不详

感谢感谢~~我就是对系统设计这块感觉没底,不知道考的啥
回复

使用道具 举报

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

本版积分规则

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