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

Citadel Campus Software Engineering OA (2020-2021)

🔗
匿名用户-KXT0R  2020-7-30 11:05:09 |倒序浏览

2020(7-9月) 码农类General 硕士 全职@citadel - 网上海投 - 在线笔试  | | Other | 应届毕业生
标题是: Citadel and Citadel Securities Campus Software Engineering Challenge (2020-2021)

您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
的序列的个数
同 LC Consecutive Numbers Sum




本帖子中包含更多资源

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

x

评分

参与人数 16大米 +40 收起 理由
燃烧的猪肉卷 + 2 很有用的信息!
jerryzzf + 1 很有用的信息!
zhangxvandy + 1 给你点个赞!
FrankBOKI + 1 给你点个赞!
SugerSJ + 2 给你点个赞!

查看全部评分


上一篇:雨林表演
下一篇:Nordstorm 电话面经
推荐
bzybc1405 2020-8-10 13:55:52 | 只看该作者
全局:
ALEXJI19991007 发表于 2020-8-3 17:13
第一题我写的答案,我网上看到的test case都过了至少……
[mw_shl_code=bash,true]public class Throttlin ...

Gateway用python直接记录每个时间点的request会有memory问题,4个test跑不过。下面这个test-case至少都过了。 觉得有用的话求加米啊!

def droppedRequests(requestTime):
    # Write your code here
    if not requestTime:
        return 0
    alldrop = 0
    reqmap = dict()
    for r in requestTime:
        reqmap[r] = reqmap.get(r, 0)+1
    # print(reqmap)
    reqpair = [(0,0)]+sorted([x for x in reqmap.items()])
    for i in range(1,len(reqpair)):
        time, cnt = reqpair[i]
        reqpair[i] = (time, reqpair[i-1][1] + cnt)
        drop = 0
        if cnt > 3:
            drop = max(drop, cnt - 3)
        j = i
        while j > 0 and time - reqpair[j][0] < 10:
            j -= 1
        if reqpair[i][1]-reqpair[j][1] > 20:
            exceed = min(cnt, reqpair[i][1]-reqpair[j][1] - 20)
            drop = max(drop, exceed)
        k = i
        while k > 0 and time - reqpair[k][0] < 60:
            k -= 1
        if reqpair[i][1]-reqpair[k][1] > 60:
            exceed = min(cnt, reqpair[i][1]-reqpair[k][1] - 60)
            drop = max(drop, exceed)
        alldrop += drop
    # print(reqpair)
    return alldrop

评分

参与人数 3大米 +4 收起 理由
燃烧的猪肉卷 + 2 很有用的信息!
Bmbmwbm + 1 欢迎分享你知道的情况,会给更多积分奖励!
zhangxvandy + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

全局:
第一题竟然全网没答案,lc上讨论的答案都过不去所以cases,老子自己钢了……天
回复

使用道具 举报

全局:
第一题我写的答案,我网上看到的test case都过了至少……
  1. public class ThrottlingGateway {
  2.     public static final int MAX_PER_SECOND = 3;
  3.     public static final int MAX_TEN_SECONDS = 20;
  4.     public static final int MAX_PER_MINUTE = 60;

  5.     public static void main(String[] args) {
  6.         int[] requestTime1 = new int[]{1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 11, 11, 11, 6, 6, 6, 5, 5, 5};
  7.         int[] requestTime2 = new int[]{1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 11, 11, 11, 11};
  8.         int[] requestTime3 = new int[]{1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  9.                 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 14, 16, 16, 16, 16, 16,
  10.                 16, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20};
  11.         ThrottlingGateway test = new ThrottlingGateway();
  12.         System.out.println(test.droppedRequests(requestTime1));
  13.     }

  14.     public int droppedRequests(int[] requestTime) {
  15.         if (requestTime == null || requestTime.length == 0) {
  16.             return 0;
  17.         }
  18.         int drop = 0;
  19.         Map<Integer, Integer> map = new HashMap<>();
  20.         int lastReqTime = 0;
  21.         for (int i : requestTime) {
  22.             map.put(i, map.getOrDefault(i, 0) + 1);
  23.             lastReqTime = Math.max(lastReqTime, i);
  24.         }
  25.         int[] nums = new int[lastReqTime + 1];
  26.         for (int i = 1; i < nums.length; ++i) {
  27.             int numReqThisSecond = map.getOrDefault(i, 0);
  28.             nums[i] = nums[i - 1] + numReqThisSecond;
  29.             if (numReqThisSecond == 0) {
  30.                 continue;
  31.             }
  32.             int toDrop = 0;
  33.             if (numReqThisSecond > MAX_PER_SECOND) {
  34.                 toDrop = Math.max(toDrop, numReqThisSecond - MAX_PER_SECOND);
  35.             }

  36.             int timeTenSecondsAgo = Math.max(i - 10, 0);
  37.             int numReqPastTenSecond = nums[i] - nums[timeTenSecondsAgo];
  38.             if (numReqPastTenSecond > MAX_TEN_SECONDS) {
  39.                 int numReqExceeded = Math.min(numReqThisSecond, numReqPastTenSecond - MAX_TEN_SECONDS);
  40.                 toDrop = Math.max(toDrop, numReqExceeded);
  41.             }

  42.             int timeOneMinuteAgo = Math.max(i - 60, 0);
  43.             int numReqPastMinute = nums[i] - nums[timeOneMinuteAgo];
  44.             if (numReqPastMinute > MAX_PER_MINUTE) {
  45.                 int numReqExceeded = Math.min(numReqThisSecond, numReqPastMinute - MAX_PER_MINUTE);
  46.                 toDrop = Math.max(toDrop, numReqExceeded);
  47.             }
  48.             drop += toDrop;
  49.         }
  50.         return drop;
  51.     }
  52. }
复制代码

评分

参与人数 2大米 +3 收起 理由
燃烧的猪肉卷 + 2 很有用的信息!
bzybc1405 + 1 给你点个赞!

查看全部评分

回复

使用道具 举报

全局:
小堆堆 发表于 2020-7-31 06:34
第一题竟然全网没答案,lc上讨论的答案都过不去所以cases,老子自己钢了……天

老哥能看一下我下面写的能过test cases不 感恩
回复

使用道具 举报

全局:
ALEXJI19991007 发表于 2020-08-03 02:14:37
老哥能看一下我下面写的能过test cases不 感恩
这种短的好过应该没问题,oa当时有十万级别的长度的case
回复

使用道具 举报

全局:
小堆堆 发表于 2020-08-03 07:56:11
这种短的好过应该没问题,oa当时有十万级别的长度的case
wtf……
回复

使用道具 举报

🔗
Victor_xy96 2020-8-6 08:31:30 | 只看该作者
全局:
666666666666666
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-RATPE  2020-8-20 07:25:28
bzybc1405 发表于 2020-8-10 13:55
Gateway用python直接记录每个时间点的request会有memory问题,4个test跑不过。下面这个test-case至少都过 ...

很多bugs呀

回复

使用道具 举报

🔗
whitenohara 2020-8-20 15:05:20 | 只看该作者
全局:
有人知道矩阵的是什么题么?差9个积分看不到。。。
回复

使用道具 举报

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

本版积分规则

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