Skip to content

Commit 5d02d8d

Browse files
authored
Create minimum-number-of-days-to-make-m-bouquets.py
1 parent e00441a commit 5d02d8d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Time: O(nlogd), d is the max day of bloomDay
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minDays(self, bloomDay, m, k):
6+
"""
7+
:type bloomDay: List[int]
8+
:type m: int
9+
:type k: int
10+
:rtype: int
11+
"""
12+
def check(bloomDay, m, k, x):
13+
result = count = 0
14+
for d in bloomDay:
15+
count = count+1 if d <= x else 0
16+
if count == k:
17+
count = 0
18+
result += 1
19+
if result == m:
20+
break
21+
return result >= m
22+
23+
if m*k > len(bloomDay):
24+
return -1
25+
left, right = 1, max(bloomDay)
26+
while left <= right:
27+
mid = left + (right-left)//2
28+
if check(bloomDay, m, k, mid):
29+
right = mid-1
30+
else:
31+
left = mid+1
32+
return left

0 commit comments

Comments
 (0)