Skip to content

Commit 1f5f779

Browse files
authored
Create maximum-number-of-upgradable-servers.py
1 parent e886fcc commit 1f5f779

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import itertools
5+
6+
7+
# math
8+
class Solution(object):
9+
def maxUpgrades(self, count, upgrade, sell, money):
10+
"""
11+
:type count: List[int]
12+
:type upgrade: List[int]
13+
:type sell: List[int]
14+
:type money: List[int]
15+
:rtype: List[int]
16+
"""
17+
# let x be the number of sold servers
18+
# (c-x)*u <= m+(x*s)
19+
# -x <= (m-c*u)//(u+s) <= 0
20+
# c-x <= c+(m-c*u)//(u+s) <= c
21+
return [min(c+(m-c*u)//(u+s), c) for c, u, s, m in itertools.izip(count, upgrade, sell, money)]

0 commit comments

Comments
 (0)