楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

Openai 挂经

 
全局:
我emerging talent面的coding的题目一样的
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-HNV3J  2024-11-25 15:39:49
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-I6LSS  2024-12-10 13:00:53
请问提示词是啥
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-WJBCP  2024-12-11 05:14:22
要面oai的可以组队一起讨论一下
fightinginterviewlin艾特gmail.com
回复

使用道具 举报

🔗
insomniaca 2024-12-12 03:35:00 | 只看该作者
全局:
感谢分享!请问能分享一下Recruiter给的面试内容提示词是什么吗?万分感谢!
回复

使用道具 举报

🔗
TassadarBruce 2024-12-12 08:40:52 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
ddw 2024-12-13 09:21:57 | 只看该作者
全局:
请问楼主,这个题是有4个part吗,做出一个菜能做下一个?还是说上来就一个大问题
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-9GEVY  2025-1-27 14:37:25
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-9GEVY  2025-1-28 06:10:21
匿名用户 发表于 2024-11-24 23:39
看了几个关于这道题的面经感觉有几个地方都说的都挺模糊的

1. Credit是按照什么顺序consume的?第一种可 ...

这题应该需要加一个条件,就是所有的timestamp随着函数调用顺序递增。隔壁楼举的例子也是这样的:https://www.1point3acres.com/bbs/thread-1098314-1-1.html
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-9GEVY  2025-2-26 01:09:43
分享下我的code。欢迎给意见。
  1. import heapq
  2. import pytest
  3. from typing import Dict, List


  4. class GPUCreditCreditID:
  5.     def __init__(self, credit_id: str) -> None:
  6.         self.credit_id = credit_id
  7.         # all ranges are inclusive
  8.         self.start_heap: List[List] = []  # [start, amount]
  9.         self.end_heap: List[List] = []  # [end, amount]
  10.         self.timestamp = 0
  11.         self.credit = 0

  12.     def check_timestamp(self, timestamp):
  13.         if timestamp <= self.timestamp:
  14.             raise Exception("Timestamp error")

  15.     def add_credit(self, amount: int, timestamp: int, expiration: int) -> None:
  16.         # self.check_timestamp(timestamp)
  17.         # self.timestamp = timestamp

  18.         heapq.heappush(self.start_heap, [timestamp, amount])
  19.         heapq.heappush(self.end_heap, [timestamp + expiration, amount])

  20.     def get_balance(self, timestamp: int) -> int:
  21.         # self.check_timestamp(timestamp)
  22.         # self.timestamp = timestamp

  23.         while self.start_heap and timestamp >= self.start_heap[0][0]:
  24.             self.credit += heapq.heappop(self.start_heap)[1]
  25.         while self.end_heap and timestamp > self.end_heap[0][0]:
  26.             self.credit -= heapq.heappop(self.end_heap)[1]

  27.         return self.credit

  28.     def use_credit(self, timestamp: int, amount: int) -> None:
  29.         self.check_timestamp(timestamp)
  30.         self.timestamp = timestamp

  31.         self.get_balance(timestamp)
  32.         if self.credit < amount:
  33.             raise Exception("No enough credit")

  34.         self.credit -= amount
  35.         while self.end_heap:
  36.             if self.end_heap[0][-1] >= amount:
  37.                 self.end_heap[0][-1] -= amount
  38.                 break
  39.             else:
  40.                 amount -= heapq.heappop(self.end_heap)[1]


  41. class GPUCredit():
  42.     def __init__(self) -> None:
  43.         self.credit_ids: Dict[str, GPUCreditCreditID] = {}
  44.    
  45.     def add_credit(self, credit_id: str, amount: int, timestamp: int, expiration: int) -> None:
  46.         if credit_id not in self.credit_ids:
  47.             self.credit_ids[credit_id] = GPUCreditCreditID(credit_id)
  48.         return self.credit_ids[credit_id].add_credit(amount, timestamp, expiration)
  49.         
  50.     def get_balance(self, credit_id: str, timestamp: int) -> int:
  51.         if credit_id not in self.credit_ids:
  52.             return 0
  53.         return self.credit_ids[credit_id].get_balance(timestamp)

  54.     def use_credit(self, credit_id: str, timestamp: int, amount: int) -> None:
  55.         if credit_id not in self.credit_ids:
  56.             raise Exception("No enough credit")
  57.         return self.credit_ids[credit_id].use_credit(timestamp, amount)


  58. def test_gpu_credit():
  59.     gc = GPUCredit()
  60.     assert gc.get_balance("openai", 0) == 0

  61.     assert gc.add_credit("apple", 10, 1, 4) == None  # [1, 5]
  62.     assert gc.get_balance("apple", 2) == 10
  63.     assert gc.use_credit("apple", 3, 3) == None
  64.     assert gc.get_balance("apple", 4) == 7
  65.     assert gc.get_balance("apple", 6) == 0

  66.     assert gc.add_credit("apple", 10, 7, 3) == None  # [7, 10]
  67.     assert gc.add_credit("apple", 10, 8, 12) == None  # [8, 20]
  68.     assert gc.use_credit("apple", 9, 5) == None
  69.     assert gc.use_credit("apple", 10, 6) == None
  70.     assert gc.get_balance("apple", 12) == 9
  71.     with pytest.raises(Exception, match="No enough credit"):
  72.         assert gc.use_credit("apple", 13, 10) == None
  73.     assert gc.use_credit("apple", 14, 9) == None

  74. pytest.main()
复制代码
回复

使用道具 举报

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

本版积分规则

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