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

Robinhood

全局:

2019(7-9月) 码农类General 硕士 全职@robinhood - 网上海投 - 技术电面  | | Other | 在职跳槽

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

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

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

评分

参与人数 2大米 +21 收起 理由
wufan3396 + 1 给你点个赞!
匿名用户-GL2HB + 20

查看全部评分


上一篇:亚麻店面0912及后续
下一篇:Square 电面
推荐
The8023 2020-5-17 05:02:37 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies

评分

参与人数 1大米 +1 收起 理由
littlestronENNN + 1 很有用的信息!

查看全部评分

回复

使用道具 举报

🔗
lbytenwater 2019-9-13 10:41:23 | 只看该作者
全局:
robinhood ? 是那个股票软件么?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-G8NHN  2019-9-22 16:35:24
请问楼主这个是电面啊
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-G8NHN  2019-9-22 16:35:38
请问楼主这个是电面吗?
回复

使用道具 举报

🔗
innerpeacecn 2019-10-25 12:49:35 | 只看该作者
全局:
可以解释下题意吗?
回复

使用道具 举报

🔗
innerpeacecn 2019-10-25 13:19:05 | 只看该作者
全局:
请问能解释下这个题意吗?
只比较a[i] 和 a[i-1] 吗 还是怎么得?
回复

使用道具 举报

🔗
johnnywsd 2020-11-2 07:37:30 | 只看该作者
全局:
  1. # coding: utf-8
  2. """
  3. [url]https://www.codenong.com/cs106206059/[/url]

  4. Given a stream of incoming "buy" and "sell" orders (as lists of limit price,
  5. quantity, and side, like ["155", "3", "buy"]),
  6. determine the total quantity (or number of "shares") executed.

  7. A "buy" order can be executed if there is a corresponding "sell" order with a
  8. price that is less than or equal to the price of the "buy" order.
  9. Similarly, a "sell" order can be executed if there is a corresponding
  10. "buy" order with a price that is greater than or equal to the price of
  11. the "sell" order. It is possible that an order does not execute
  12. immediately if it isn't paired to a counterparty. In that case,
  13. you should keep track of that order and execute it at a later
  14. time when a pairing order is found. You should ensure that
  15. orders are filled immediately at the best possible price.
  16. That is, an order should be executed when it is processed,
  17. if possible. Further, "buy" orders should execute at the
  18. lowest possible price and "sell" orders at the highest possible
  19. price at the time the order is handled.

  20. Note that orders can be partially executed.



  21. --- Sample Input ---

  22. orders = [
  23. ['150', '5', 'buy'], # Order A
  24. ['190', '1', 'sell'], # Order B
  25. ['200', '1', 'sell'], # Order C
  26. ['100', '9', 'buy'], # Order D
  27. ['140', '8', 'sell'], # Order E
  28. ['210', '4', 'buy'], # Order F
  29. ]

  30. Sample Output
  31. 9

  32. 思路:这题老实讲,不难,只是题目意思理解费劲,解题关键是用两个priorityqueue,一个用来存buy的最大,一个用来存sell的最小。

  33. 然后扫描,update 两个pq;
  34. """


  35. import heapq


  36. class Solution:

  37.     def __init__(self):
  38.         self.buy = []
  39.         self.sell = []
  40.         self.count = 0

  41.     def put_order(self, order):
  42.         price, quantity, side = order
  43.         price = int(price)
  44.         quantity = int(quantity)
  45.         if side == 'buy':
  46.             # max-heap
  47.             heapq.heappush(self.buy, (-price, price, quantity))
  48.         elif side == 'sell':
  49.             # min-heap
  50.             heapq.heappush(self.sell, (price, price, quantity))
  51.         
  52.         self.fulfill()

  53.     def stream(self, orders):
  54.         for order in orders:
  55.             self.put_order(order)

  56.     def fulfill(self):
  57.         while self.buy and self.sell:
  58.             b_key, b_price, b_quantity = self.buy[0]
  59.             s_key, s_price, s_quantity = self.sell[0]
  60.             if b_price >= s_price:
  61.                 heapq.heappop(self.buy)
  62.                 heapq.heappop(self.sell)
  63.                 if b_quantity < s_quantity:
  64.                     heapq.heappush(self.sell, (s_key, s_price, s_quantity - b_quantity))
  65.                 elif b_quantity > s_quantity:
  66.                     heapq.heappush(self.buy, (b_key, b_price, b_quantity - s_quantity))
  67.                 self.count += min(s_quantity, b_quantity)
  68.             else:
  69.                 break


  70. import unittest

  71. class Test(unittest.TestCase):

  72.     def test_1(self):
  73.         sol = Solution()
  74.         orders = [
  75.             ['150', '5', 'buy'], # Order A
  76.             ['190', '1', 'sell'], # Order B
  77.             ['200', '1', 'sell'], # Order C
  78.             ['100', '9', 'buy'], # Order D
  79.             ['140', '8', 'sell'], # Order E
  80.             ['210', '4', 'buy'], # Order F
  81.         ]
  82.         sol.stream(orders)
  83.         print(sol.count)
  84.         self.assertEqual(sol.count, 9)

  85.     def test_2(self):
  86.         sol = Solution()
  87.         orders = [
  88.             ['150', '5', 'buy'], # Order A
  89.             ['190', '1', 'sell'], # Order B
  90.             ['200', '1', 'sell'], # Order C
  91.             ['100', '9', 'buy'], # Order D
  92.             ['140', '8', 'sell'], # Order E
  93.             ['210', '100', 'buy'], # Order F
  94.         ]
  95.         sol.stream(orders)
  96.         print(sol.count)
  97.         self.assertEqual(sol.count, 10)

  98.     def test_3(self):
  99.         sol = Solution()
  100.         orders = [
  101.             ['210', '100', 'buy'], # Order F
  102.             ['190', '1', 'sell'], # Order B
  103.             ['200', '1', 'sell'], # Order C
  104.             ['100', '9', 'buy'], # Order D
  105.             ['140', '8', 'sell'], # Order E
  106.             ['150', '5', 'buy'], # Order A
  107.         ]
  108.         sol.stream(orders)
  109.         print(sol.count)
  110.         self.assertEqual(sol.count, 10)

  111.     def test_4(self):
  112.         sol = Solution()
  113.         orders = [
  114.             ("150", "10", "buy"),
  115.             ("165", "7", "sell"),
  116.             ("168", "3", "buy"),
  117.             ("155", "5", "sell"),
  118.             ("166", "8", "buy")
  119.         ]
  120.         sol.stream(orders)
  121.         print(sol.count)
  122.         self.assertEqual(sol.count, 11)

  123. if __name__=="__main__":
  124.     unittest.main(verbosity=2)
复制代码
回复

使用道具 举报

🔗
dragonlee888 2021-3-28 23:58:32 | 只看该作者
全局:
应该是比较a[i] 和 a[i-1]
回复

使用道具 举报

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

本版积分规则

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