def min_max_weight(weights: List[int], d: int) → int:
# WRITE YOUR BRILLIANT CODE HERE
required_days = d
left, right = max(weights), sum(weights)
while left < right:
total_days, cur_sum_weights = 1, 0
mid = (left + right) // 2
for w in weights:
if cur_sum_weights + w > mid:
total_days += 1
cur_sum_weights = 0
cur_sum_weights += w
if total_days > required_days:
left = mid + 1
else:
right = mid
return left
}
it shortens the range by a bit by comparing max element in the weight array with sum of elements divided by no. of days,
as the ans is always be greater or equal to by sum of elements divided by no.of days
}
it shortens the range by a bit by comparing max element in the weight array with sum of elements divided by no. of days, as the ans is always be greater or equal to by sum of elements divided by no.of days
@mod: I am not able to see the solutions that I had written in the Try it yourself section.
I was able to see all of my solutions written in Try it yourself , but now it has disappeared.
Please let me know how to fix this ?
I believe the time complexity of this would be O(n log n). O(log n) for the binary search and O(n) for the helper function. Space complexity should be O(1) or O(n) if the array is counted. Could be wrong on this though.
I think this question would benefit a bit from a little more explanation. I checked out the problem on another platform and was able to understand a bit easier.