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

robinhood onsite 原题

全局:

2020(7-9月) 码农类General 本科 实习@robinhood - 内推 - Onsite  | | Fail | 应届毕业生

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

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

x
did my onsite yesterday and got rejected today
Problem:
A trade is defined as a string containing the 4 properties given below separated by commas:

Symbol (4 alphabetical characters, left-padded by spaces)
Side (either "B" or "S" for buy or sell)
Quantity (4 digits, left-padded by zeros)
ID (6 alphanumeric characters)
e.g.
"AAPL,B,0100,ABC123"

which represents a trade of a buy of 100 shares of AAPL with ID "ABC123"

Given two lists of trades - called "house" and "street" trades, write code to create groups of matches between trades and return a list of unmatched house an
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
ell). Prioritize exact and attribute matches over offsetting matches. Prioritize matching the earliest lexicographical buy with the earliest lexicographical sell.

[execution time limit] 4 seconds (py)

[input] array.string house_trades

[input] array.string street_trades

[output] array.string

A list of unmatched trades both house and street, ordered alphabetically

评分

参与人数 4大米 +32 收起 理由
yanmoviola + 2 很有用的信息!
zxzczvb + 3 很有用的信息!
动漫小子 + 2 很有用的信息!
匿名用户-PSKPE + 25

查看全部评分


上一篇:2020 quora intern
下一篇:Quora 掛經 & 資料分享
推荐
ByronHsu 2021-9-30 07:36:40 | 只看该作者
全局:
本帖最后由 ByronHsu 于 2021-9-29 16:39 编辑
  1. def filter_cross_matched(trade1, trade2, isMatched):
  2.     trade1 = sorted(trade1)[::-1] # largest to smallest, so we can pop from right
  3.     trade2 = sorted(trade2)[::-1]
  4.     unmatched1 = []
  5.     unmatched2 = []
  6.     while trade1 and trade2:
  7.         if isMatched(trade1[-1], trade2[-1]):
  8.             trade1.pop()
  9.             trade2.pop()
  10.         elif trade1[-1] > trade2[-1]:
  11.             unmatched2.append(trade2.pop())
  12.         elif trade1[-1] < trade2[-1]:
  13.             unmatched1.append(trade1.pop())

  14.     # the remaining in trade1 / trade2 are also unmatched
  15.     unmatched1 += trade1
  16.     unmatched2 += trade2
  17.     return unmatched1, unmatched2

  18. def filter_inner_matched(trade, isMatched):
  19.     B_list = [t for t in trade if t.split(",")[1] == "B"]
  20.     S_list = [t for t in trade if t.split(",")[1] == "S"]
  21.     B_list, C_list = filter_cross_matched(B_list, S_list, isMatched)
  22.     return sorted(B_list + C_list)


  23. def solution(house_trades, street_trades):
  24.     # exact match
  25.     # key = symbol + type + quantity + id
  26.     isExact = lambda x,y: x == y
  27.     house_trades, street_trades = filter_cross_matched(house_trades, street_trades, isExact)
  28.    
  29.     # fuzzy match
  30.     # key = (symbol + type + quantity, id)
  31.     isFuzzy = lambda x,y: x.split(",")[:3] == y.split(",")[:3]
  32.     house_trades, street_trades = filter_cross_matched(house_trades, street_trades, isFuzzy)
  33.    
  34.     # offsetting match
  35.     isOffsetMatched = lambda x, y: x.split(",")[0] + x.split(",")[2] == y.split(",")[0] + y.split(",")[2]
  36.     house_trades, street_trades = filter_inner_matched(house_trades, isOffsetMatched), filter_inner_matched(street_trades, isOffsetMatched)

  37.     ans = sorted(house_trades + street_trades)
  38.     return ans
复制代码

评分

参与人数 2大米 +2 收起 理由
杰瑞米米 + 1 给你点个赞!
211014 + 1 这段代码太优美了老哥

查看全部评分

回复

使用道具 举报

全局:
Hi Do you have any questions except coding?
like front end or OOD?
回复

使用道具 举报

🔗
 楼主| iwantanintern 2019-11-2 09:18:07 | 只看该作者
全局:
  1. def match(curr_house, curr_street):
  2.     return curr_house.strip() == curr_street.strip()

  3. def match_attribute(curr_house, curr_street):
  4.     h_items = curr_house.split(',')
  5.     s_items = curr_street.split(',')
  6.     for i in range(0,3):
  7. [i]        if h_items != s_items:
  8.             return False
  9.     return True

  10. def helper(house_trades, street_trades, match_function):
  11.     # first sort the two lists
  12.     house_trades = sorted(house_trades)[::-1]
  13.     street_trades = sorted(street_trades)[::-1]
  14.     p_house = 0
  15.     p_street = 0
  16.     unmatched_house = []
  17.     unmatched_street = []
  18.     while house_trades and street_trades:
  19.         # peak the top elements
  20.         curr_house = house_trades[-1]
  21.         curr_street = street_trades[-1]
  22.         # if there is a match, advance two pointers
  23.         if match_function(curr_house, curr_street):
  24.             house_trades.pop()
  25.             street_trades.pop()
  26.         elif curr_house < curr_street:
  27.             # this means curr_house will never be matched
  28.             unmatched_house.append(curr_house)
  29.             house_trades.pop()
  30.         else:
  31.             # this means curr_street will never be matched
  32.             unmatched_street.append(curr_street)
  33.             street_trades.pop()
  34.     return unmatched_house + house_trades, unmatched_street + street_trades

  35. def compare_trades(house_trades, street_trades):
  36.     # first match exact
  37.     h_left, s_left = helper(house_trades, street_trades, match)
  38.     # next run the next iteration match
  39.     h_left_2, s_left_2 = helper(h_left, s_left, match_attribute)
  40.     return sorted(h_left_2+s_left_2)
复制代码
[/i]

评分

参与人数 1大米 +8 收起 理由
匿名用户-PSKPE + 8

查看全部评分

回复

使用道具 举报

🔗
 楼主| iwantanintern 2019-11-2 09:19:43 | 只看该作者
全局:
don't quite remember the algo/system design rounds so I will answer no more questions
回复

使用道具 举报

🔗
211014 2021-11-26 07:19:40 | 只看该作者
全局:
这段代码太优美了老哥
回复

使用道具 举报

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

本版积分规则

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