Skip to content

Commit 0adbcd0

Browse files
author
hasibulislam999
committed
Minimize Maximum of Array problem solved
1 parent cf2b24e commit 0adbcd0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Title: Minimize Maximum of Array
3+
* Description: You are given a 0-indexed array nums comprising of n non-negative integers.
4+
* Author: Hasibul Islam
5+
* Date: 08/04/2023
6+
*/
7+
8+
/**
9+
* @param {number[]} nums
10+
* @return {number}
11+
*/
12+
var minimizeArrayValue = function (nums) {
13+
let sum = 0,
14+
res = 0;
15+
for (let i = 0; i < nums.length; ++i) {
16+
sum += nums[i];
17+
res = Math.max(res, Math.floor((sum + i) / (i + 1)));
18+
}
19+
return res;
20+
};
21+
22+
module.exports = minimizeArrayValue;

0 commit comments

Comments
 (0)