123
返回列表 发新帖
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

狗司店面和昂赛

🔗
nicezg 2020-9-19 06:09:22 | 只看该作者
全局:
那果断不去啊,给L3 羞辱你。换个公司
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-GBLJ1  2020-9-19 11:35:33
第四题大家有什么思路吗?  感觉好像要DFS?

回复

使用道具 举报

🔗
oumizx 2020-9-21 14:55:23 | 只看该作者
全局:
请问下第一题可以讲下打印出所有interval的oncall的思路吗? 用calendar的方法只能得出所有重合的区间,是不是在treemap里面value存一个set里面有当前的所有人。 可以每次print一个时间点吗?
回复

使用道具 举报

🔗
oumizx 2020-9-21 16:17:38 | 只看该作者
全局:
写了一下第一题
  1. public class PrintOncall {

  2.     class Oncall {
  3.         List<String> namesToAdd;
  4.         List<String> namesToRemove;

  5.         public Oncall() {
  6.             this.namesToAdd = new LinkedList<>();
  7.             this.namesToRemove = new LinkedList<>();
  8.         }
  9.     }

  10.     class Result {
  11.         int[] interval;
  12.         List<String> names;

  13.         public Result(int[] interval, List<String> names) {
  14.             this.interval = interval;
  15.             this.names = names;
  16.         }
  17.     }

  18.     public List<Result> solution(List<String> names, List<List<int[]>> intervals) {
  19.         TreeMap<Integer, Oncall> map = new TreeMap<>();
  20.         int n = names.size();
  21.         for (int i = 0; i < n; i++) {
  22.             String name = names.get(i);
  23.             List<int[]> curIntervals = intervals.get(i);
  24.             for (int[] interval : curIntervals) {
  25.                 int start = interval[0];
  26.                 int end = interval[1];
  27.                 Oncall toAdd = map.getOrDefault(start, new Oncall());
  28.                 toAdd.namesToAdd.add(name);
  29.                 map.put(start, toAdd);
  30.                 Oncall toRemove = map.getOrDefault(end, new Oncall());
  31.                 toRemove.namesToRemove.add(name);
  32.                 map.put(end, toRemove);
  33.             }
  34.         }

  35.         Set<String> curNames = new HashSet<>();
  36.         List<Result> res = new LinkedList<>();
  37.         for (Map.Entry<Integer, Oncall> entry : map.entrySet())  {
  38.             int idx = entry.getKey();
  39.             List<String> namesToRemove = entry.getValue().namesToRemove;
  40.             List<String> namesToAdd = entry.getValue().namesToAdd;


  41.             Map.Entry<Integer, Oncall>  prevEntry = map.lowerEntry(idx);
  42.             if (prevEntry != null) {
  43.                 int prevIdx = prevEntry.getKey();
  44.                 res.add(new Result(new int[]{prevIdx, idx}, new LinkedList<>(curNames)));
  45.             }

  46.             for (String name : namesToRemove) {
  47.                 curNames.remove(name);
  48.             }

  49.             for (String name : namesToAdd) {
  50.                 curNames.add(name);
  51.             }
  52.         }

  53.         return res;
  54.     }

  55.     public static void main(String[] args) {
  56.         List<String> names = new LinkedList<>();
  57.         names.add("Peter");
  58.         names.add("Jane");
  59.         List<List<int[]>> intervals = new LinkedList<>();
  60.         List<int[]> intervals1 = new LinkedList<>();
  61.         intervals1.add(new int[]{1, 3});
  62.         List<int[]> intervals2 = new LinkedList<>();
  63.         intervals2.add(new int[]{0, 2});
  64.         intervals2.add(new int[]{3, 4});
  65.         intervals.add(intervals1);
  66.         intervals.add(intervals2);
  67.         PrintOncall solution = new PrintOncall();
  68.         List<Result> res = solution.solution(names, intervals);
  69.         for (Result cur : res) {
  70.             System.out.println(Arrays.toString(cur.interval));
  71.             System.out.println(cur.names);
  72.         }
  73.     }

  74.     // Input
  75.     // Peter     ______
  76.     // Jane   ______   ____
  77.     //        0  1  2  3  4


  78.     // Expected output
  79.     // [[Jane], [[0, 1]]], [[Peter, Jane], [[1, 2]]], [[Peter], [[2, 3]]], [[Jane], [[3, 4]]]
  80. }
复制代码


Output:
  1. [0, 1]
  2. [Jane]
  3. [1, 2]
  4. [Peter, Jane]
  5. [2, 3]
  6. [Peter]
  7. [3, 4]
  8. [Jane]

  9. Process finished with exit code 0
复制代码
回复

使用道具 举报

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

使用道具 举报

地里匿名用户
🔗
匿名用户-TGFCF  2020-9-22 08:19:15
litJordan 发表于 2020-9-22 05:56
a.b[1]直接对应了{"e": "f"},里面并没有c这个key,请问LZ为什么这里"f"?是不是input是a.b[1].e?这样结 ...

you are right!
回复

使用道具 举报

🔗
marvinbai 2020-9-22 14:14:56 | 只看该作者
全局:
回复

使用道具 举报

🔗
oumizx 2020-9-29 06:06:22 | 只看该作者
全局:
请问下lz第四轮是什么思路
回复

使用道具 举报

🔗
belljay 2021-1-17 13:09:30 | 只看该作者
全局:
第四题可以用Gson直接parse JSON String吗?感觉考JSON Parser的implementation也太过分了。
回复

使用道具 举报

🔗
chuyang 2021-2-2 04:53:15 | 只看该作者
全局:
belljay 发表于 2021-1-17 13:09
第四题可以用Gson直接parse JSON String吗?感觉考JSON Parser的implementation也太过分了。

面试的时候问过面试官了,不能用 。。
回复

使用道具 举报

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

本版积分规则

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