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

Indeed OA 15

全局:

2016(7-9月) 码农类General 硕士 全职@indeed - 内推 - 在线笔试  | | Other | 应届毕业生
刚做的Indeed OA 15,挂了两个test case 4跟6,估计是挂了。附上写的代码,求大神帮忙debug。hackerrank不能看到test case是什么,真的很坑
[size=100%][size=100%]
[size=100%]1


[size=100%]import java.io.*;
[size=100%][size=100%]
[size=100%]2


[size=100%]import java.util.*;
[size=100%][size=100%]
[size=100%]3


[size=100%]
[size=100%][size=100%]
[size=100%]4

[size=100%][size=100%][size=1.25em]▾



[size=100%]public class Solution {
[size=100%][size=100%]
[size=100%]5

[size=100%][size=100%][size=1.25em]▾



[size=100%]    public static void main(String args[] ) throws Exception {
[size=100%][size=100%]
[size=100%]6


[size=100%]        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
[size=100%][size=100%]
[size=100%]7


[size=100%]        Scanner sc = new Scanner(System.in);
[size=100%][size=100%]
[size=100%]8


[size=100%]        int Q = sc.nextInt();
[size=100%][size=100%]
[size=100%]9


[size=100%]        int M = sc.nextInt();
[size=100%][size=100%]
[size=100%]10


[size=100%]        Pair[] pairs = new Pair[M];
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
   static class Pair{

[size=100%][size=100%]
[size=100%]44


[size=100%]        public int val = 0;
[size=100%][size=100%]
[size=100%]45


[size=100%]        public int count = 0;
[size=100%][size=100%]
[size=100%]46

[size=100%][size=100%][size=1.25em]▾



[size=100%]        public Pair(int val, int count) {
[size=100%][size=100%]
[size=100%]47


[size=100%]            this.val = val;
[size=100%][size=100%]
[size=100%]48


[size=100%]            this.count = count;
[size=100%][size=100%]
[size=100%]49


[size=100%]        }
[size=100%][size=100%]
[size=100%]50


[size=100%]    }
[size=100%][size=100%]
[size=100%]51


[size=100%]}


本帖子中包含更多资源

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

x

上一篇:Linkedin Intern OA
下一篇:【Coursera oa1 面经】新题!给的sample都是错的!真是给跪了!
🔗
 楼主| helloc93 2016-10-2 16:18:38 | 只看该作者
全局:
  1. 1

  2. import java.io.*;
  3. 2

  4. import java.util.*;
  5. 3



  6. 4

  7. ▾

  8. public class Solution {
  9. 5

  10. ▾

  11.     public static void main(String args[] ) throws Exception {
  12. 6

  13.         /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  14. 7

  15.         Scanner sc = new Scanner(System.in);
  16. 8

  17.         int Q = sc.nextInt();
  18. 9

  19.         int M = sc.nextInt();
  20. 10

  21.         Pair[] pairs = new Pair[M];
  22. 11

  23. ▾

  24.         for (int i = 0; i < M; i++) {
  25. 12

  26.             pairs[i] = new Pair(sc.nextInt(), sc.nextInt());
  27. 13

  28.         }
  29. 14

  30.         int[] res = calculate(pairs, Q);
  31. 15

  32.         for (int n: res) System.out.println(n);
  33. 16

  34.     }
  35. 17


  36. 18

  37. ▾

  38.     public static int[] calculate(Pair[] pairs, int Q) {
  39. 19

  40.         if (pairs.length == 0 || Q < 2) return new int[0];
  41. 20


  42. 21

  43. ▾

  44.         Arrays.sort(pairs, new Comparator<Pair>(){
  45. 22

  46. ▾

  47.             public int compare(Pair a, Pair b) {
  48. 23

  49.                 return a.val-b.val;
  50. 24

  51.             }
  52. 25

  53.         });
  54. 26


  55. 27

  56.         int[] indexs = new int[pairs.length];
  57. 28

  58.         int sum = 1;
  59. 29

  60. ▾

  61.         for (int i = 0; i < indexs.length; i++) {
  62. 30

  63.             indexs[i] = sum;
  64. 31

  65.             sum += pairs[i].count;
  66. 32

  67.         }
  68. 33


  69. 34

  70.         int[] res = new int[Q-1];
  71. 35

  72. ▾

  73.         for (int k = 1; k < Q; k++) {
  74. 36

  75.             int index = Arrays.binarySearch(indexs, (int)Math.ceil(((double)pairs.length)*k/Q));
  76. 37

  77.             if (index < 0) index = -index-1;
  78. 38

  79.             res[k-1] = pairs[index].val;
  80. 39

  81.         }
  82. 40

  83.         return res;
  84. 41

  85.     }
  86. 42


  87. 43

  88. ▾

  89.     static class Pair{
  90. 44

  91.         public int val = 0;
  92. 45

  93.         public int count = 0;
  94. 46

  95. ▾

  96.         public Pair(int val, int count) {
  97. 47

  98.             this.val = val;
  99. 48

  100.             this.count = count;
  101. 49

  102.         }
  103. 50

  104.     }
  105. 51

  106. }
复制代码
回复

使用道具 举报

🔗
 楼主| helloc93 2016-10-2 16:19:16 | 只看该作者
全局:
第一次在帖子了插入代码,不会搞。。
回复

使用道具 举报

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

使用道具 举报

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

本版积分规则

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