Skip to content

Commit a25bf67

Browse files
authored
Merge pull request #3535 from aadil42/patch-79
Create 2439-minimize-maximum-of-array.js
2 parents 133db7a + 6595464 commit a25bf67

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Time O(n) | Space O(1)
3+
* @param {number[]} nums
4+
* @return {number}
5+
*/
6+
var minimizeArrayValue = function(nums) {
7+
8+
let currTotal = nums[0];
9+
let max = nums[0];
10+
11+
for (let i = 1; i < nums.length; i++) {
12+
currTotal += nums[i];
13+
max = Math.max(max, Math.ceil(currTotal / (i + 1)));
14+
}
15+
return max;
16+
};

0 commit comments

Comments
 (0)