Skip to content

solves minimize maximum of the array (#2439) in python #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2439: minimize maximum of the array
  • Loading branch information
sumanth-botlagunta committed Apr 5, 2023
commit 21be543a4083f3861a6c96485121fba9dae495c9
12 changes: 12 additions & 0 deletions python/minimize_maximum_of_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://leetcode.com/problems/minimize-maximum-of-array/description/
# T:O(n) where n is the number of elements in the array
# S:O(1)

class Solution:
def minimizeArrayValue(self, nums: List[int]) -> int:
minimumValue = 0
prefixSum = 0
for i, num in enumerate(nums):
prefixSum += num
minimumValue = max(minimumValue,((prefixSum+i)//(i+1)))
return minimumValue