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

亚麻 OA

🔗
匿名用户-PJBLM  2022-4-14 21:01:46 |倒序浏览

2022(4-6月) 码农类General 硕士 全职@amazon - 猎头 - 在线笔试  | 😐 Neutral 😐 Average | Other | 在职跳槽

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

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

x
亚麻一轮 在线测试 一共两题

1. 输入一串 操作 包括 插入订单号, 和 发货 , 如果 订单满三个就可以发货, 返回 三个订单号, 否则 返回 NA. 通过大部分测试, 但还是有三个超时了
2
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
res= [4,2, .....]  , res[i] 代表 MEX=i 时 的子数组数量.

大家有什么比较高效的解法?

评分

参与人数 3大米 +7 收起 理由
匿名用户-VGW5H + 5
jerrysxj63 + 1 给你点个赞!
gallagherwww + 1 很有用的信息!

查看全部评分


上一篇:Aurora sde intern 挂经
下一篇:新鲜巨硬80 min OA
推荐
yenristine 2022-5-19 06:51:43 | 只看该作者
全局:
MEX =1 的subarray不应该是[0], [4,0],[0,2], [4,0,2] 4个吗
回复

使用道具 举报

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

使用道具 举报

🔗
hanzhaogang 2022-4-14 22:53:27 | 只看该作者
全局:
能详细说下第二题吗?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-DUBWQ  2022-4-16 08:33:20
毫无思路,今晚就OA了
回复

使用道具 举报

🔗
minghaocui 2022-4-16 13:21:47 | 只看该作者
全局:
代码没有贴好, 重新贴一下
  1.     public List<Integer> calculateMEX(int[] nums)
  2.     {
  3.         
  4.         List<Integer> ret = new ArrayList<>();
  5.         Map<Integer, Integer> indexes = new HashMap<>();
  6.         int n = nums.length;
  7.         //assume no duplicates
  8.         int remaining = getTotalSubarray(n);
  9.         for (int i = 0; i < n; i++)
  10.         {
  11.             indexes.put(nums[i], i);
  12.         }
  13.         
  14.         int min = n;
  15.         int max = 0;
  16.         int currNum = 0;
  17.         
  18.         while (remaining > 0)
  19.         {
  20.             if (!indexes.containsKey(currNum))
  21.             {
  22.                 // if element currNum is not present, that means all remaining subarray will return currNum
  23.                 ret.add(remaining);
  24.                 remaining = 0;
  25.             }
  26.             else
  27.             {
  28.                 // index of currNum
  29.                 int currIndex = indexes.get(currNum);
  30.                 min = Math.min(min, currIndex);
  31.                 max = Math.max(max, currIndex);
  32.                 // all element from 0 ... to currNum are located between position min to max
  33.                 // so find all of those subarray with 0 ... currNum included.
  34.                 // a little trick is that , we just need to take away subarrays on the both end from the total subarrays
  35.                 // the middle part can be viewed as one single group when calculating.
  36.                 // we need to exclude them from the remaining.
  37.                 int excluding = getTotalSubarray(n - (max - min)) - getTotalSubarray(min) - getTotalSubarray(n - max -1);
  38.                 ret.add(remaining - excluding);
  39.                 // these are the total number of subarrays that should return at least currNum + 1
  40.                 // i.e. they all included values from 0 to currNum.
  41.                 remaining = excluding;
  42.             }
  43.             currNum ++;
  44.         }
  45.         
  46.         return ret;
  47.         
  48.     }
  49.    
  50.    
  51.     private int getTotalSubarray(int n)
  52.     {
  53.         //an array of n elements has n * (n + 1) / 2 subarrays
  54.         return n * (n + 1) / 2;
  55.     }
复制代码

评分

参与人数 2大米 +2 收起 理由
andy1996 + 1 给你点个赞!
midumiaodu + 1 思路非常对。点赞

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-DUBWQ  2022-4-17 00:31:26
这个array里面的数字是unique的吗?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-MBXLA  2022-4-18 04:00:25 来自APP
lz 我积分还不够 看不到第二题是什么 可以麻烦发一下第二题吗 麻烦了
回复

使用道具 举报

🔗
yenristine 2022-5-21 02:23:44 | 只看该作者
全局:
第二题能有重复数吗
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-JTU6Q  2022-6-21 07:56:11
yenristine 发表于 2022-5-18 18:51
MEX =1 的subarray不应该是[0], [4,0],[0,2], [4,0,2] 4个吗

请问为啥[4] [2] 不算在MEX = 1的subarray里?
回复

使用道具 举报

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

本版积分规则

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