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) <= k2.
Example 1:
Input: nums = [3,7,5]
Output: 3
Explanation:
When k = 3, nonPositive(nums, k) = 6 <= k2.
nums[0] = 3 one time. nums[0] becomes 3 - 3 = 0.nums[1] = 7 three times. nums[1] becomes 7 - 3 - 3 - 3 = -2.nums[2] = 5 two times. nums[2] becomes 5 - 3 - 3 = -1.Example 2:
Input: nums = [1]
Output: 1
Explanation:
When k = 1, nonPositive(nums, k) = 1 <= k2.
nums[0] = 1 one time. nums[0] becomes 1 - 1 = 0.
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 105Solutions for this problem are being prepared.
Try solving it yourselfPractice Minimum K to Reduce Array Within Limit with our built-in code editor and test cases.
Practice on FleetCode