Last active
April 5, 2023 07:21
-
-
Save sanket1729/8e65400a94d83906a8cdba30792417d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def minimizeArrayValue(self, nums: List[int]) -> int: | |
total_sum = 0 | |
ans = 0 | |
for i, v in enumerate(nums): | |
capacity = ans * (i + 1) | |
total_sum += v | |
# Can we accomodate last value within current answer | |
if total_sum > capacity: | |
# Restribute equally. | |
ans = math.ceil(total_sum/(i + 1)) | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment