LeetCode 2439, Medium. Topics: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:
Problem
You are given a 0-indexed array nums comprising of n non-negative integers.
In one operation, you must:
- Choose an integer
i such that 1 <= i < n and nums[i] > 0.
- Decrease
nums[i] by 1.
- Increase
nums[i - 1] by 1.
Return the minimum possible value of the maximum integer of nums after performing any number of operations.
Examples
Constraints
- n == nums.length
- 2 <= n <= 10^5
- 0 <= nums[i] <= 10^9
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026