Minimum K to Reduce Array Within Limit
You are given a positive integer array nums.
For a positive integer k, define nonPositive(nums, k) as the minimum number of operations needed to make every element of nums non-positive. In one operation, you can choose an index i and reduce nums[i] by k.
Return an integer denoting the minimum value of k such that nonPositive(nums, k) <= k^2.
Example 1
Input
nums = [3,7,5]Output
3When k = 3, reducing 3 once, 7 three times, and 5 twice makes every element non-positive using 6 operations, and 6 <= 3^2.
Example 2
Input
nums = [1]Output
1When k = 1, reducing the only element once makes it 0, so nonPositive(nums, k) = 1 <= 1^2.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5