注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
刚做完OA1,一小时后收到了OA2邮件
70分钟两道题
Q1: Findminhealth
Amazon prime is designing a game. the player needs to pass n rounds sequentially in this game. Rules for the palyer are:
The player loses power[i] health to complete round i, the player's health must be greater than 0 at all times. the player can choose to use armor in any one round. the armor will prevent damage of min(armor,power[i]).
Determine the minimum starting health for a player to with the game
Example:
Power = [1,2,6,7]
armor = 5
Give the player 12 units of health at,7].Their shipping cost is 1 + 4 + 5 + 7 = 17, which is minimal . Return 17
解题思路:
def MinCostShipping(parcels, k):
count = k - len(parcels)
res = 0
i = 1
while count > 0:
if i not in parcels:
res += 1
count -= 1
i += 1
return res
testcase:11/15. 结束后在网上查了下用set的方式时间能优化
|