📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

现金程序全套挂经

🔗
匿名用户-1HMUO  2024-10-5 00:06:32 |倒序浏览

2024(7-9月) 码农类General 硕士 全职@cashapp - 网上海投 - Onsite  | 😐 Neutral 😐 Average | Fail | 在职跳槽

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

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

x
五轮。

第一轮coding。白人小哥。完了想不起面哪道题啊。想起来再发。小哥人还好,题也不难印象中。

第二轮coding。像是西班牙小哥,还有一个sha
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies



一个星期后recruiter发邮件说挂了。说system design 不行。
  1. class Solution {
  2.   public static void main(String[] args) {
  3.         Evaluator evaluator1 = new Evaluator(2, 0.05);
  4. // Data array: [210.0, 185.0, 200.0]
  5. // Read in 210.0, average is 210.0
  6. // Read in 185.0, average is 210.0 - dip found
  7. // Read in 200.0, average is 205.0

  8.         System.out.println(evaluator1.ingestData(210.0));
  9.         System.out.println(evaluator1.ingestData(185.0));

  10.         System.out.println(evaluator1.ingestData(200.0));

  11.         //2nd test case
  12.         // Data array: [505.2, 454.68, 553.32, 892.7, 499.76, 88.23, 477.1]
  13.       // Read in 505.2, average is 505.2.
  14.       // Read in 454.68, average is 479.94 =>
  15.       // Read in 553.32, average is 479.94 - spike found.
  16.       // Read in 892.7, average is 479.94 - spike found.
  17.       // Read in 499.76, average is 477.22 =>
  18.       // Read in 88.23, average is 477.22 - dip found.
  19.       // Read in 477.1, average is 488.43
  20.         Evaluator evaluator2 = new Evaluator(2, 0.05);
  21.       double[] input2 = new double[]{505.2, 454.68, 553.32, 892.7, 499.76, 88.23, 477.1};
  22.       System.out.println("========Test Case 2======");

  23.       for (double num: input2) {
  24.         System.out.println(evaluator2.ingestData(num));
  25.       }
  26.   }

  27. //   private static void useCase1() {
  28. //         // 1st test case
  29. //     // Sliding window size: 2
  30. //     // Data array: [210.0, 185.0, 200.0]
  31. //     // Read in 210.0, average is 210.0
  32. //     // Read in 185.0, average is 197.5
  33. //     // Read in 200.0, average is 192.5

  34. //     // Evaluator evaluator = new Evaluator(2);
  35. //     // System.out.println(evaluator.ingestData(210.0));
  36. //     // System.out.println(evaluator.ingestData(185.0));
  37. //     // System.out.println(evaluator.ingestData(200.0));

  38. //     // 2nd test case
  39. //     // Sliding window size: 2
  40. //     // Data array: [505.2, 454.68, 553.32, 892.7, 499.76, 88.23, 477.1]
  41. //     // Read in 505.2, average is 505.2
  42. //     // Read in 454.68, average is 479.94
  43. //     // Read in 553.32, average is 504.0
  44. //     // Read in 892.7, average is 723.01
  45. //     // Read in 499.76, average is 696.23
  46. //     // Read in 88.23, average is 294.0
  47. //     // Read in 477.1, average is 282.67
  48. //     Evaluator evaluator2 = new Evaluator(2);

  49. //     double[] input2 = new double[]{505.2, 454.68, 553.32, 892.7, 499.76, 88.23, 477.1};
  50. //     System.out.println("========Test Case 2======");

  51. //     for (double num: input2) {
  52. //       System.out.println(evaluator2.ingestData(num));
  53. //     }

  54. //     // last test case
  55. // //     Sliding window size: 5
  56. //     // Data array: [780.0, 331.0, 412.0, 403.0, 978.0, 372.0, 306.0, 355.0, 698.0, 487.0]
  57. //     // Read in 780.0, average is 780.0
  58. //     // Read in 331.0, average is 555.5
  59. //     // Read in 412.0, average is 507.67
  60. //     // Read in 403.0, average is 481.5
  61. //     // Read in 978.0, average is 580.8
  62. //     // Read in 372.0, average is 499.2
  63. //     // Read in 306.0, average is 494.2
  64. //     // Read in 355.0, average is 482.8
  65. //     // Read in 698.0, average is 541.8
  66. //     // Read in 487.0, average is 443.6

  67. //     System.out.println("========Test Case 3======");

  68. //     Evaluator evaluator3 = new Evaluator(5);

  69. //     double[] input3 = new double[]{780.0, 331.0, 412.0, 403.0, 978.0, 372.0, 306.0, 355.0, 698.0, 487.0};

  70. //     for (double num: input3) {
  71. //       System.out.println(evaluator3.ingestData(num));
  72. //     }
  73. //   }
  74. }

  75. class Evaluator {
  76.   int k;
  77.   Queue<Double> queue;
  78.   double currSum;
  79.   double currAverage;
  80.   double threshold;
  81.   public Evaluator(int windowSize, double threshold) {
  82.     this.k = windowSize;
  83.     this.threshold = threshold;
  84.     this.queue = new LinkedList<>();
  85.     this.currSum = 0;
  86.     this.currAverage = 0;
  87.   }

  88.   public double ingestData(double next) {
  89.     // currAverage => threahold [a, b];
  90.     // potentail incoming average => newAverage;

  91.     // is this a dip or a spike
  92.     // if yes, ignore it
  93.     // if not, continue ingesting the data

  94.     // first data point is always accepted

  95.     if (queue.isEmpty()) {
  96.       queue.add(next);
  97.       currSum += next;  
  98.       double val = currSum / queue.size();
  99.       currAverage = (double) Math.round(val * 100) / 100; // round to 2 decimal point
  100.       return currAverage;
  101.     }

  102.     double[] thresholds = new double[] {currAverage * ( 1 - threshold), currAverage * (1 + threshold)};

  103.     // incoming average

  104.     // curretn data poitns + incoming datapoint  <= k
  105.     if ((queue.size() + 1) <= k) {
  106.       double newAverage = (currSum + next) / (queue.size() + 1);

  107.       if (newAverage < thresholds[0]) {
  108.         // ignore this data point. but also indicate the dip found
  109.         System.out.println("Dip found");
  110.         return currAverage;
  111.       }
  112.       if (newAverage > thresholds[1]) {
  113.         // ignore this data point. but also indicate the dip found
  114.         System.out.println("Spike found");
  115.         return currAverage;
  116.       }
  117.       queue.add(next);
  118.       currSum += next;
  119.       double val = currSum / queue.size();
  120.       currAverage = (double) Math.round(val * 100) / 100; // round to 2 decimal point
  121.       return currAverage;
  122.     }

  123.     // queue is going to be overflow with new data point

  124.     double newAverage = (currSum + next - queue.peek()) / k;
  125.     if (newAverage < thresholds[0]) {
  126.         // ignore this data point. but also indicate the dip found
  127.         System.out.println("Dip found");
  128.         return currAverage;
  129.     }
  130.     if (newAverage > thresholds[1]) {
  131.         // ignore this data point. but also indicate the dip found
  132.         System.out.println("Spike found");
  133.         return currAverage;
  134.     }
  135.     System.out.println("incoming " + next + " currSum " + ((currSum + next - queue.peek()) /2 ) + " currAverage: " + currAverage + " newAverage " + newAverage + " queue size " + queue.size());
  136.     System.out.println(thresholds[0] + " " + thresholds[1]);
  137.     queue.add(next);
  138.     currSum += next - queue.remove();
  139.     currAverage = (double) Math.round(newAverage * 100) / 100; // round to 2 decimal point
  140.     return currAverage;

  141.     // curr data points + incoming data point > k

  142.     // // return the moving average for the last k data points;
  143.     // queue.add(next);
  144.     // currSum += next;

  145.     // if (queue.size() > k) {
  146.     //   currSum -= queue.remove();
  147.     // }
  148.     // double val = currSum / queue.size();
  149.     // currAverage = (double) Math.round(val * 100) / 100; // round to 2 decimal point
  150.     // return currAverage;
  151.   }
  152. }
复制代码

评分

参与人数 1大米 +10 收起 理由
匿名用户-FGYB6 + 10 欢迎分享你知道的情况,会给更多大米奖励!

查看全部评分


上一篇:下个门全套挂经
下一篇:SoFi 电面过经
地里匿名用户
🔗
匿名用户-ZZDGM  2024-11-27 16:50:49
请问hotel reservation system着重问哪些功能? 是搜索,预订还是支付? 这几个都Dive Deep感觉时间来不及啊           
以及对consistency和idempotency方面问的细吗,谢谢!
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-1HMUO  2024-11-30 15:37:48 来自APP
匿名用户 发表于 2024-11-27 00:50:49
请问hotel reservation system着重问哪些功能? 是搜索,预订还是支付? 这几个都Dive Deep感觉时间来不及啊
看看alex xu。基本都是自己讲。没着重问啥。感觉面试官就问一下clarify的问题
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-ZZDGM  2024-12-1 09:13:51
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
回复

使用道具 举报

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

本版积分规则

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