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

Stripe店面

全局:

2022(1-3月) 码农类General 硕士 全职@stripe - 网上海投 - 技术电面 视频面试  | 😃 Positive 🙂 Easy | Other | 在职跳槽

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

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

x
刚面完,有点懊恼,最后一步花太久时间了,面试官小姐姐超级友善,然而依然生死难料。。。

题目还是老题 mutually ranked list,面试官在coderpad里贴了题,自带一个简单的unit test框架,而且test cases都给写好了,最后跑过就好,会followup问一下还有哪些test cases可以加,但是不要求写。

唯一要注意的是存wishlist的data structure是Map<String, String[]>,所以username啥的都是String,我自己准备的时候都是用的int,然后整了个二维数组存,所以不少corner case的测试就很简单了,结果面试官不让用int存,换成string还挺麻烦的,既要看username是不是在map里,还要注意返回的String[]会不会有index out of boundary exception。最后一个test case老是不过调到后面心态都要崩了。。。唉

题目贴下面,省得各位到处找了。求大米。
/***
* Part 1
* Imagine an Airbnb-like vacation rental service, where users in different cities can exchange their apartment with another user for a week.
* Each user compiles a wishlist of the apartments they like.
* These wishlists are ordered, so the top apartment on a wishlist is that user's first choice for where they would like to spend a vacation.
* You will be asked to write part of the code that will help an algorithm find pairs of users who would like to swap with each other.
*
* Given a set of users, each with an *ordered* wishlist of other users' apartments:
*   a's wishlist: c d
*   b's w
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
t of the change, if it were to take place.
* Call your function changed_pairings()
*
* // if d's second choice becomes their first choice, a and d will no longer be a mutually ranked pair
* changed_pairings('d', 1) // returns ['a']
*
* // if b's third choice becomes their second choice, c and b will become a mutually ranked pair (mutual second-choices)
* changed_pairings('b', 2) // returns ['c']
*
* // if b's second choice becomes their first choice, no mutually-ranked pairings are affected
* changed_pairings('b', 1) // returns []
*
*/

评分

参与人数 5大米 +22 收起 理由
Redmond + 1 给你点个赞!
justinrao + 1 很有用的信息!
chiproeng + 1 赞一个
tiancaihxx + 1 欢迎分享你知道的情况,会给更多积分奖励!
匿名用户-G838Q + 18

查看全部评分


上一篇:athenahealth电面
下一篇:雨林实习timeline+不知道过不过经+准备的想法
地里匿名用户
🔗
匿名用户-XF0Z6  2022-2-16 05:53:54
感谢楼主,请问你说的最后一个不过的test case是  changed_pairings('b', 1)吗?可以允许修改input data吗?
回复

使用道具 举报

🔗
 楼主| kamarkaka 2022-2-17 03:44:16 | 只看该作者
全局:
我当时应该是卡在倒数第二个testcase,有那个array index out of boundary exception
应该可以改,但是没必要
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-XQLX2  2022-2-17 22:54:33
好人一生平安
回复

使用道具 举报

全局:
换成map之后,这两个condition确实需要注意。 谢谢楼主提醒。
回复

使用道具 举报

🔗
wza13579 2022-3-7 15:09:43 | 只看该作者
全局:
匿名者 发表于 2022-2-15 13:53
感谢楼主,请问你说的最后一个不过的test case是  changed_pairings('b', 1)吗?可以允许修改input data吗 ...

我觉得可以改了,等你算完之后再revert回来就好了
回复

使用道具 举报

🔗
荀小舟WCRC 2022-4-22 12:45:47 | 只看该作者
全局:
这题用个二位数组就可以了吧。 大家觉得这个方案可行的话,求个大米
  1. data = {
  2. 'a': ['c', 'd'],
  3. 'b': ['d', 'a', 'c'],
  4. 'c': ['a', 'b'],
  5. 'd': ['c', 'a', 'b']
  6. }

  7. userMapping={
  8.     "a":0,
  9.     "b":1,
  10.     "c":2,
  11.     "d":3
  12. }
  13. reverseUserMapping=[user for user in userMapping.keys()]
  14. numOfPlayer=len(data)
  15. metric=[[None]*numOfPlayer for i in range(0, numOfPlayer)]

  16. for k,preferences in data.items():
  17.     row_num=userMapping.get(k)
  18.     counter=0
  19.     for p in preferences:
  20.         col_num=userMapping.get(p)
  21.         metric[row_num][col_num]=counter
  22.         counter+=1
  23. print(metric)
  24. def has_mutual_first_choice(user):
  25.     user_id=userMapping.get(user)
  26.     first_choice=metric[user_id].index(0)
  27.     if metric[first_choice].index(0)==user_id:
  28.         return True
  29.     return False

  30. # print(has_mutual_first_choice('a')) # true
  31. # print(has_mutual_first_choice('b'))  # false


  32. def has_mutual_pair_for_rank(user, rank):
  33.     user_id=userMapping.get(user)
  34.    
  35.     first_choice=metric[user_id].index(rank)
  36.     if rank in metric[first_choice] and metric[first_choice].index(rank)==user_id:
  37.         return True
  38.     return False
  39. # print(has_mutual_pair_for_rank('a', 0)) # true (a and c)
  40. # print(has_mutual_pair_for_rank('b', 1)) # true (a and d are mutually each others'print()

  41. def changed_pairings(user, rank):
  42.     user_id=userMapping.get(user)
  43.     upgraded_user=metric[user_id].index(rank)
  44.     downgrad_user=metric[user_id].index(rank-1)
  45.     is_upgraded_user_mutual_before=has_mutual_pair_for_rank(user, rank)
  46.     is_downgrad_user_mutual_before=has_mutual_pair_for_rank(user, rank-1)
  47.    
  48.     metric[user_id][upgraded_user]=rank-1
  49.     metric[user_id][downgrad_user]=rank
  50.    
  51.     is_upgraded_user_mutual_after=has_mutual_pair_for_rank(user, rank-1)
  52.     is_downgrad_user_mutual_after=has_mutual_pair_for_rank(user, rank)
  53.     result=set()
  54.     if is_upgraded_user_mutual_before != is_upgraded_user_mutual_after:
  55.         result.add(reverseUserMapping[upgraded_user])
  56.     if is_downgrad_user_mutual_before != is_downgrad_user_mutual_after:
  57.         result.add(reverseUserMapping[downgrad_user])
  58.     metric[user_id][upgraded_user]=rank
  59.     metric[user_id][downgrad_user]=rank-1
  60.     return list(result)
  61.    
  62.    
  63.    

  64. print(changed_pairings('d', 1) )
  65. # ['a']
  66. # if b's third choice becomes their second choice, c and b will become a mutually ranked pair (mutual second-choices)
  67. print(changed_pairings('b', 2))
  68. # returns ['c']
  69. # if b's second choice becomes their first choice, no mutually-ranked pairings are affected
  70. print(changed_pairings('b', 1))
  71. # returns []
复制代码
回复

使用道具 举报

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

本版积分规则

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