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

Uber L5a 店面挂经

全局:

2022(7-9月) 码农类General 硕士 全职@uber - 猎头 - 技术电面  | 🙁 Negative 😣 Hard | Fail | 在职跳槽

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

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

x
最近越面越差,现在店面已经过不了了,面到了一道没见过的题目。
We have a freight train that services stations on a rail line. The train makes stops at these stations to load and unload packages.

Every day each station indicates the packages available for the train to pickup and the packages it can receive from the train.

When the train makes a sto
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
ion(zero indexed)   1   2   4   5
Drop                    0   1   4   7   ->  Max total deliveries = 12
Pickup                  6   1   5   0
Loads Onboard the train 6   6   7   0

感觉有点像利口 1235,当时现场没做出来。。。
如果觉得有帮助,请大家加点大米,感谢!

评分

参与人数 3大米 +14 收起 理由
concise + 1 楼主/层主请继续!
匿名用户-EJQGN + 12
SDKmanager + 1 给你点个赞!

查看全部评分


上一篇:领英 6月末 Infra track VO 挂经
下一篇:高盛intern 8.24新鲜OA
全局:
这jb题目跟个小作文似的
回复

使用道具 举报

推荐
axel981109 2022-8-25 15:30:02 | 只看该作者
全局:
最近正好在刷题,随便写了个python dp的解。 准确性和效率我都没怎么测,只是给大家提供点思路
  1. dp={}
  2. def helper(index,load):
  3.    
  4.     if index in dp and load<=dp[index][0]:
  5.         return min(load,dp[index][1])
  6.    
  7.     if index>=len(triplets):
  8.         return 0
  9.     pickup,drop,skip=triplets[index]
  10.     pick_up_skip=index+max(1+skip,1)

  11.     result=max(helper(index+1,load),min(drop,load)+helper(pick_up_skip,load-min(drop,load)+pickup))
  12.     dp[index]=(load,result)
  13.     return result
  14. def solution():
  15.     return helper(0,0)
复制代码

评分

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

查看全部评分

回复

使用道具 举报

地里匿名用户
🔗
匿名用户-WGZ85  2022-8-25 11:39:21
LZ加油!主要是最近形势不好,祝早日拿offer!
回复

使用道具 举报

🔗
SDKmanager 2022-8-26 14:04:17 | 只看该作者
全局:
topdown dp + memorizaiton 感觉可以解,或者从后向前的bottom up dp?
感觉有点像复杂版本的house robber
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-MA1GG  2022-8-31 09:16:07
axel981109 发表于 2022-8-25 03:30
最近正好在刷题,随便写了个python dp的解。 准确性和效率我都没怎么测,只是给大家提供点思路

测试了一下您的解法,拿楼主的例子,应该是12,但是这个解法好像是return了11。麻烦大佬帮忙优化一下,在准备电面,怕遇到这道就跪了
回复

使用道具 举报

🔗
maxentropy 2022-8-31 11:25:25 | 只看该作者
全局:
匿名用户 发表于 2022-8-30 18:16
测试了一下您的解法,拿楼主的例子,应该是12,但是这个解法好像是return了11。麻烦大佬帮忙优化一下,在 ...

这个题我也写了一下,代码其实很短,但复杂度不低:没发现简单的贪心思路, 所以要穷举所有可能性。
  1. def max_transaction(station_stripets):
  2.         mem = {}
  3.         def helper(i, curr):
  4.                 if (i, curr) in mem:
  5.                         return mem[(i, curr)]
  6.                 if i>=len(station_stripets):
  7.                         return 0
  8.                 pick, receive, skip =  station_stripets[i]
  9.                 ret = max(helper(i+1, curr), helper(i+1+skip, max(0, curr-receive)+pick)+min(curr, receive))
  10.                 mem[(i, curr)]=ret
  11.                 return ret
  12.         return helper(0, 0)

  13. station_stripets = [[4,0,2], [6,2,0], [1,1,0], [4,4,1], [5,4,0], [4,10,0]]
  14. print(max_transaction(station_stripets))
复制代码
回复

使用道具 举报

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

使用道具 举报

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

本版积分规则

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