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

食跩普店面

🔗
匿名用户-ZEPTY  2021-10-9 09:04:44 |倒序浏览

2022(10-12月) 码农类General 硕士 实习@stripe - 网上海投 - 视频面试  | 😃 Positive 😐 Average | Other | 应届毕业生

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

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

x
Wishlist 原题

说至少要做两问,做到第三问最好。


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

评分

参与人数 1大米 +5 收起 理由
地里的生活菌 + 5 给你点个赞!

查看全部评分


上一篇:巨硬 2021 10月初 招聘事件 面经
下一篇:苹果 CPU physical electrical analysis engineer面经
地里匿名用户
🔗
匿名用户-25QL5  2021-10-9 10:14:14
关于第三问,如果swap之后在指定的index没有mutual rank,那是不是就return original mutual rank 就行了?
回复

使用道具 举报

🔗
ACMilanShare 2021-10-9 15:41:04 | 只看该作者
全局:
楼主什么时候面的呀?有没有收到后续
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-W4CPP  2021-10-16 03:06:27
Let's crack stripe!
  1. /*
  2.   Mutual Ranking
  3.   Question comes from https://www.1point3acres.com/bbs/thread-769296-1-1.html
  4.                       https://www.1point3acres.com/bbs/thread-674646-1-1.html
  5.                       https://www.1point3acres.com/bbs/thread-793699-1-1.html
  6.                       https://www.1point3acres.com/bbs/thread-806739-1-1.html


  7.    user and wishlist represented with Map<Character, Character[]> wishlist
  8.    a, [b,c,d]
  9.    b, [a,c,d]
  10.    c, [d,a]
  11.    d, [a,c]
  12.    index 0 is the highest rank

  13.    question 1: boolean hasMutualFirstChoice(String username)
  14.                mutual at the first rank
  15.    question 2: boolean hasMutualRanking(char, int),
  16.                hasMutualRanking(a, 1) = true
  17.                explain:   a's  ranking 1 is c, c's ranking 1 is a.
  18.                hasMutualRanking(a, 0) = true

  19.    question 3-1
  20.               changePair(char user, int index) :swap user rank index with index-1
  21.               return matched all users before and after swap with same mutual ranking

  22.               changePair(c,1) then c ranking list is [a,d]
  23.               result is [a, d], because before swap result is a, after swap result is d


  24.               a -> [b, c, d],
  25.               b -> [a, d, c],
  26.               c -> [d, a, b],
  27.               d -> [a, c].

  28.               changePair(c, 1)
  29.               result is a b d

  30.               Every wishlist entry in the network is either "mutually ranked" or "not mutually ranked"
  31.               depending on the rank the other user gives that user's apartment in return.

  32.               The most common operation in the network is incrementing the rank of a single wishlist entry on a single user.
  33.               This swaps the entry with the entry above it in that user's list.
  34.               Imagine that, when this occurs, the system must recompute the "mutually-ranked-ness" of any pairings that
  35.               may have changed.

  36.               Write a function that takes a username and a rank representing the entry whose rank is being bumped up.
  37.               Return an array of the users whose pairings with the given user *would* gain or lose mutually-ranked
  38.               status as a result of the change, if it were to take place.
  39.               Call your function changed_pairings()
  40.               data = {
  41.                'a': ['c', 'd'],
  42.                'b': ['d', 'a', 'c'],
  43.                'c': ['a', 'b'],
  44.                'd': ['c', 'a', 'b'],
  45.               }
  46.               if d's second choice becomes their first choice, a and d will no longer be a mutually ranked pair
  47.               changed_pairings('d', 1) // returns ['a']

  48.               if b's third choice becomes thei‍‌‍‌‌‍‍‌‍‍‌‍‌‍‍‍‍‌r second choice, c and b will become a mutually ranked pair (mutual second-choices)
  49.               changed_pairings('b', 2) // returns ['c']

  50.               if b's second choice becomes their first choice, no mutually-ranked pairings are affected
  51.               changed_pairings('b', 1) // returns []

  52.               if d's second choice becomes their first choice, a and d will no longer be a mutually ranked pair
  53.               if b's third choice becomes their second choice, c and b will become a mutually ranked pair (mutual second-choices)
  54.               if b's second choice becomes their first choice, no mutually-ranked pairings are affected

  55.     question 3-2
  56.      after swap(rank, rank -1)
  57.      return the changed part of mutual list.


  58.    question 4 Anti-ra‍‌‍‌‌‍‍‌‍‍‌‍‌‍‍‍‍‌nk
  59.      boolean hasAntiMutualRank(char user)
  60.      a: [b,c,d]  b is a's first rank,
  61.      b: [d,c,a]  a is b's last rank

  62.    boolean hasAntiMutualRankWithSwapOption(char user) can swap
  63.      assume: index 0 and 1 swap
  64.              index N-1 and N-1 swap


  65.     */
  66.   private Map<Character, Character[]> wish;

  67.   public MutualRanking(Map<Character, Character[]> wishList) {
  68.     wish = wishList;
  69.   }

  70.   public boolean hasMutualFirstChoice(char user) {
  71.     return hasMutualRanking(user, 0, 0, false);
  72.   }
  73.   // rank is 0-based
  74.   public boolean hasMutualRanking(char user, int rank) {
  75.     return hasMutualRanking(user, rank, rank, false);
  76.   }

  77.   private boolean hasMutualRanking(char user, int myRank, int muRank) {
  78.     return hasMutualRanking(user, myRank, muRank, false);
  79.   }

  80.   public Character[] changePair(char user, int rank) {
  81.     char u = user;
  82.     int r = rank;
  83.     if (wish.containsKey(u) && wish.get(u).length > r) {
  84.       List<Character> ans = new ArrayList<>();
  85.       Character[] iwish = wish.get(u);
  86.       for (int i = 0; i <= iwish.length; i++) {
  87.         if (hasMutualRanking(u, i)) ans.add(iwish[i]); // as usual
  88.       }
  89.       if (r > 0) {
  90.         // swap index and index-1
  91.         if (hasMutualRanking(u, r, r - 1)) ans.add(iwish[r]);
  92.         if (hasMutualRanking(u, r - 1, r)) ans.add(iwish[r - 1]);
  93.       }

  94.       Character[] a = new Character[ans.size()];
  95.       return ans.toArray(a);
  96.     }
  97.     return new Character[0];
  98.   }
  99.   /*
  100.   after swap(rank, rank -1)
  101.   the changed part of mutual list. do not change the provided wishlist map
  102.   */
  103.   Character[] changed_pairings(char user, int index) {
  104.     char u = user;
  105.     int i = index;
  106.     if (wish.containsKey(u) && wish.get(u).length > i) {
  107.       ArrayList<Character> r = new ArrayList<>();
  108.       Character[] iwish = wish.get(u);
  109.       if (i > 0) {
  110.         if (hasMutualRanking(u, i) != hasMutualRanking(u, i, i - 1)) r.add(iwish[i]);
  111.         if (hasMutualRanking(u, i - 1) != hasMutualRanking(u, i - 1, i)) r.add(iwish[i - 1]);
  112.       }
  113.       Character[] a = new Character[r.size()];
  114.       return r.toArray(a);
  115.     }
  116.     return new Character[0];
  117.   }

  118.   /*
  119.   a: [b,c,d]  b is a's first rank,
  120.   b: [d,c,a]  a is b's last rank
  121.    */
  122.   boolean hasAntiMutualRank(char user) {
  123.     return hasMutualRanking(user, 0, 0, true);
  124.   }

  125.   private boolean hasMutualRanking(char user, int uRank, int muRank, boolean anti) {
  126.     if (uRank < 0) return false;
  127.     if (wish.containsKey(user) && wish.get(user).length > uRank) {
  128.       char mu = wish.get(user)[uRank];
  129.       return wish.containsKey(mu)
  130.           && wish.get(mu).length > muRank
  131.           && wish.get(mu)[anti ? (wish.get(mu).length - 1 - muRank) : muRank].equals(user);
  132.     }
  133.     return false;
  134.   }
  135.   /*
  136.   Followup: can swap
  137.   assume:
  138.   index 0 and 1 swap
  139.   index N-1 and N-1 swap
  140.    */
  141.   boolean hasAntiMutualRankWithSwapOption(char user) {
  142.     return false;
  143.   }

  144.   public static void main(String[] args) {
  145.     Map<Character, Character[]> wish = new HashMap<>();
  146.     wish.put('a', new Character[] {'b', 'c', 'd'});
  147.     wish.put('b', new Character[] {'a', 'c', 'd'});
  148.     wish.put('c', new Character[] {'d', 'a'});
  149.     wish.put('d', new Character[] {'a', 'c'});

  150.     MutualRanking t = new MutualRanking(wish);
  151.     System.out.println(t.hasMutualRanking('a', 1));
  152.     System.out.println(t.hasMutualRanking('a', 9) == false);
  153.     System.out.println(t.hasMutualRanking('a', 0));
  154.     System.out.println(Arrays.toString(t.changePair('a', 1)).equals("[b, c]"));
  155.     System.out.println(Arrays.toString(t.changePair('a', 9)).equals("[]"));

  156.     wish = new HashMap<>();
  157.     wish.put('a', new Character[] {'b', 'c', 'd'});
  158.     wish.put('b', new Character[] {'a', 'd', 'c'});
  159.     wish.put('c', new Character[] {'d', 'a', 'b'});
  160.     wish.put('d', new Character[] {'a', 'c'});
  161.     t = new MutualRanking(wish);
  162.     System.out.println(Arrays.toString(t.changePair('c', 1)).equals("[a, b, d]"));

  163.     wish = new HashMap<>();
  164.     wish.put('a', new Character[] {'b', 'c', 'd'});
  165.     wish.put('b', new Character[] {'a', 'c'});
  166.     wish.put('c', new Character[] {'d', 'a'});
  167.     wish.put('d', new Character[] {'c', 'b'});
  168.     t = new MutualRanking(wish);
  169.     System.out.println(Arrays.toString(t.changed_pairings('a', 1)).equals("[c, b]"));
  170.     System.out.println(Arrays.toString(t.changed_pairings('a', 2)).equals("[c]"));

  171.     wish = new HashMap<>();
  172.     wish.put('a', new Character[] {'b', 'c', 'd'});
  173.     wish.put('b', new Character[] {'d', 'c', 'a'});
  174.     wish.put('c', new Character[] {'d', 'a'});
  175.     wish.put('d', new Character[] {'c', 'b'});
  176.     t = new MutualRanking(wish);
  177.     System.out.println((t.hasAntiMutualRank('a')));
  178.   }
复制代码
求米 求米
回复

使用道具 举报

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

本版积分规则

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