Minimize Maximum of Array
You are given a 0-indexed array nums comprising of n non-negative integers.
In one operation, you must:
- Choose an integer
isuch that1 <= i < nandnums[i] > 0. - Decrease
nums[i]by1. - Increase
nums[i - 1]by1.
Return the minimum possible value of the maximum integer of nums after performing any number of operations.
Example 1
Input
nums = [3,7,1,6]Output
5After the shown optimal operations,
nums becomes [5, 5, 2, 5] with maximum value 5, and the maximum cannot be less than 5.Example 2
Input
nums = [10,1]Output
10It is optimal to leave
nums as is, and since 10 is the maximum value, we return 10.Constraints
- n == nums.length
- 2 <= n <= 10^5
- 0 <= nums[i] <= 10^9