Choose a minimum positive integer k so the array can be reduced until every value is within a required limit.
You are given an integer array nums and a limit limit. In one operation, you may choose a positive integer k and reduce any array element x so that its new value becomes ceil(x / k).
Your task is to find the smallest positive integer k such that, after applying this reduction to every element of the array, the maximum value in the transformed array is at most limit.
In other words, find the minimum k for which:
nums[i], the value ceil(nums[i] / k) is less than or equal to limit.If multiple k values work, return the smallest one.
n, the size of the array.n integers nums[0..n-1].limit.For the LeetCode version, the input is provided as the array nums and the integer limit.
Return the smallest positive integer k such that replacing every nums[i] with ceil(nums[i] / k) makes all values at most limit.
1 <= n <= $10^{5}$1 <= nums[i] <= $10^{9}$1 <= limit <= $10^{9}$These are prep-oriented constraints and may not exactly match the original platform statement.
Example 1
Input
nums = [5, 8, 10], limit = 3
Output
4
Explanation
For k = 4, the transformed array is [ceil(5/4), ceil(8/4), ceil(10/4)] = [2, 2, 3], and the maximum is 3, which meets the limit. Any smaller k would leave at least one value above 3.
Example 2
Input
nums = [1, 2, 3], limit = 2
Output
2
Explanation
For k = 2, the transformed array becomes [1, 1, 2], so the maximum is 2. k = 1 does not work because the maximum would still be 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.