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

stripe 电面

🔗
匿名用户-CXLFR  2021-10-14 04:55:12 |倒序浏览

2022(4-6月) 码农类General 硕士 全职@stripe - 网上海投 - 技术电面  | 😃 Positive 🙂 Easy | Pass | 应届毕业生

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

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

x
面到的是wishlist,面之前没仔细看,后来看了下,应
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
自己加一些。面完过了两天收到下一轮。

评分

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

查看全部评分


上一篇:黑车OA
下一篇:狗家 奇葩 Onsite + Timeline
地里匿名用户
推荐
匿名用户-JICHG  2021-10-16 02:40:43
no worry, let's crack the stripe
  1. import java.util.*;

  2. public class MutualRanking {
  3.   /*
  4.   Mutual Ranking
  5.   Question comes from https://www.1point3acres.com/bbs/thread-769296-1-1.html
  6.                       https://www.1point3acres.com/bbs/thread-674646-1-1.html
  7.                       https://www.1point3acres.com/bbs/thread-793699-1-1.html
  8.                       https://www.1point3acres.com/bbs/thread-806739-1-1.html


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

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

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

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


  26.               a -> [b, c, d],
  27.               b -> [a, d, c],
  28.               c -> [d, a, b],
  29.               d -> [a, c].

  30.               changePair(c, 1)
  31.               result is a b d

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

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

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

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

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

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

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


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

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


  67.     */
  68.   private Map<Character, Character[]> wish;

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

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

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

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

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

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

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

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

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

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

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

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

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

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