-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsolution.py
More file actions
36 lines (28 loc) · 810 Bytes
/
Copy pathsolution.py
File metadata and controls
36 lines (28 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution:
def canMake(self, ranks, n, time):
donuts = 0
for r in ranks:
curr_time = 0
k = 0
while True:
curr_time += r * (k + 1)
if curr_time > time:
break
k += 1
donuts += k
if donuts >= n:
return True
return False
def minTime(self, ranks, n):
min_rank = min(ranks)
low = 0
high = min_rank * n * (n + 1) // 2
ans = high
while low <= high:
mid = (low + high) // 2
if self.canMake(ranks, n, mid):
ans = mid
high = mid - 1
else:
low = mid + 1
return ans