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

硬币店面挂经

🔗
匿名用户-G6WGE  2022-4-30 05:07:40 |倒序浏览

2022(4-6月) 码农类General 本科 全职@coinbase - 内推 - 技术电面  | 😐 Neutral 😐 Average | Fail | 在职跳槽

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

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

x
https://www.1point3acres.com/bbs/thread-792448-1-1.html 这个题的变种,感觉地里没有
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies





补充内容 (2022-04-30 06:09 +8:00):
挂了。拒信发的很快,不到俩小时

评分

参与人数 3大米 +7 收起 理由
WordHelo + 1 给你点个赞!
匿名用户-QBFAI + 5
arcovitcher + 1 给你点个赞!

查看全部评分


上一篇:Expedia OA 2022
下一篇:Experian Software Engineer Intern OA
地里匿名用户
推荐
匿名用户-IXIWF  2022-5-31 01:26:00
感谢楼主分享(已经给楼主加米)

抛砖引玉了,大致想法是,根据buy transaction构建一个queue, FIFO,
每次卖的时候,
- 如果队列的第一个buy_transaction够卖,就卖指定的数额,更新第一个buy_transaction
- 如果不够卖,出队列,然后去下一个buy_transaction,直到卖到指定的数额或者队列为空
  1. from collections import deque

  2. class Transaction:
  3.    
  4.     def __init__(self, date: int, amount: int, price: float, type: str) -> None:
  5.         self.date = date
  6.         self.amount = amount
  7.         self.unit_price = price / amount
  8.         self.type = type
  9.         
  10.     def __str__(self) -> str:
  11.         return "date=" + self.date + ", amount=" + self.amount + ", unit_price=" + self.unit_price
  12.         
  13. def print_sell(buy_transaction, sell_transaction, amount_sold) -> str:
  14.     proceeds = sell_transaction.unit_price * amount_sold
  15.     gain = amount_sold * (sell_transaction.unit_price - buy_transaction.unit_price)
  16.     info = "sell(date=" + str(sell_transaction.date) + ", date_acquire=" + str(buy_transaction.date) + ", amount=" + str(amount_sold) + ", proceeds=" + str(proceeds) + ", gain=" + str(gain)
  17.     print(info)
  18.    
  19. def handle_buy_transaction(positions: deque, transaction: Transaction) -> None:
  20.     positions.append(transaction)

  21. def handle_sell_transaction(positions: deque, transaction: Transaction) -> None:
  22.     if transaction.type != "sell":
  23.         return
  24.    
  25.     sell_amount = transaction.amount
  26.    
  27.     while sell_amount > 0 and len(positions) > 0:
  28.         first_trans = positions[0]
  29.         if first_trans.amount > sell_amount:
  30.             # this transaction has enough amount to sell
  31.             print_sell(first_trans, transaction, sell_amount)
  32.             first_trans.amount = first_trans.amount - sell_amount
  33.             sell_amount = 0  # we don't need to sell anymore
  34.         else:
  35.             # this transaction doesn't have enough amount to sell
  36.             print_sell(first_trans, transaction, first_trans.amount)
  37.             first_trans = positions.popleft()
  38.             sell_amount = sell_amount - first_trans.amount  # we still need to sell
  39.    
  40. def statement(inputs):
  41.     # a queue of all 'buy' transactions
  42.     positions = deque([])
  43.    
  44.     for input in inputs:
  45.         # 1. build transaction
  46.         transaction = Transaction(input["date"], input["amount"], input["price"], input["type"])
  47.         
  48.         # 2. handle transaction
  49.         if input['type'] == "buy":
  50.             handle_buy_transaction(positions, transaction)
  51.         elif input["type"] == "sell":
  52.             handle_sell_transaction(positions, transaction)
  53.             
  54. ###################################
  55. ## Execution starts here
  56. ###################################
  57. inputs = [
  58.     {"date": 1, "amount": 5, "price": 25.0, "type": "buy"},
  59.     {"date": 2, "amount": 20, "price": 60.0, "type": "buy"},
  60.     {"date": 3, "amount": 7, "price": 42.0, "type": "sell"},
  61.     {"date": 4, "amount": 6, "price": 30.0, "type": "sell"},
  62.     {"date": 5, "amount": 5, "price": 25.0, "type": "buy"},
  63.     {"date": 6, "amount": 5, "price": 25.0, "type": "buy"},
  64. ]

  65. statement(inputs)
复制代码
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-G6WGE  2022-5-3 10:21:54
匿名者 发表于 2022-5-2 22:03
请问楼主,output里面的gain的计算逻辑是什么呀?

哦我打错了,第一条应该是5.
day3,以6刀的价格卖了5个day1买的成本5刀的🪙,gain = 5 * (42 / 7 - 25 / 5)
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-MI8XT  2022-5-3 10:03:11
请问楼主,output里面的gain的计算逻辑是什么呀?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-NZRW1  2022-5-4 00:42:53
请问楼主,怎么算proceeds呀?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-DGMIB  2022-5-4 12:08:27
Sell(date: 3, date_acquire=2, amount= 2, proceeds=12.0, gain=2.0)
这个从哪来的?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-G6WGE  2022-5-28 12:26:22
匿名者 发表于 2022-5-4 00:08
Sell(date: 3, date_acquire=2, amount= 2, proceeds=12.0, gain=2.0)
这个从哪来的?

什么从哪来的?这是code输出的
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-G6WGE  2022-5-28 12:27:55
匿名者 发表于 2022-5-3 12:42
请问楼主,怎么算proceeds呀?

第三天总共出售7个🪙,价格42,所以单价6
这其中5个是第一天买的,所以proceeds = 6*5
回复

使用道具 举报

🔗
bcxc 2022-5-29 10:40:25 | 只看该作者
全局:
觉得这道题应该预先处理下数据, 比如计算出每股价格,盈亏(+/—),之后计算起来比较容易。
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-UUQUI  2022-5-30 00:50:27 来自APP
用queue把,买往后放,卖从前面拿。简化点就卖要去update head,如果head少于要卖的数量,结构简单点就一个coin算一个queue item,卖几个就拿几次,这样就不需要考虑是update还是删除了
回复

使用道具 举报

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

本版积分规则

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