Minimize Maximum of Array

Medium Topics Company Tags

You may transfer one unit from an entry at index i > 0 to the entry immediately to its left, provided the source entry is positive. Repeat any number of times. Return the smallest possible maximum entry of nums.

Example 1:

Input: nums = [0,9,0]

Output: 5

Explanation: Transfer four units from index 1 to index 0, giving [4,5,0] with maximum 5. The first two entries must still sum to 9, so their maximum cannot be below 5.

Example 2:

Input: nums = [8,0]

Output: 8

Explanation: The first entry cannot send units left, so it cannot decrease from 8. The original maximum of 8 is already optimal.

Example 3:

Input: nums = [0,0]

Output: 0

Explanation: Both entries are already 0, and no positive entry is available for a transfer. The maximum stays 0.

Constraints:

  • 2 <= nums.length <= 100000
  • 0 <= nums[i] <= 1000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.