Loading...
You are given an integer array nums and an integer k.
Consider an operation where you pick any one element and replace it with two positive integers that sum to the original value. For example, an element equal to 5 can be replaced by 1 and 4, or by 2 and 3.
Given that you can perform this operation at most k times, return the smallest possible value the maximum element of nums can reach.
Input: nums = [9], k = 2
Output: 3
Explanation:
- Replace 9 with 6 and 3. [9] -> [6,3].
- Replace 6 with 3 and 3. [6,3] -> [3,3,3].
The maximum element is 3, so return 3.
Input: nums = [2,4,8,2], k = 4
Output: 2
Explanation:
- Replace 8 with 4 and 4. [2,4,8,2] -> [2,4,4,4,2].
- Replace a 4 with 2 and 2. [2,4,4,4,2] -> [2,2,2,4,4,2].
- Replace a 4 with 2 and 2. [2,2,2,4,4,2] -> [2,2,2,2,2,4,2].
- Replace a 4 with 2 and 2. [2,2,2,2,2,4,2] -> [2,2,2,2,2,2,2,2].
The maximum element is 2, so return 2.
nums.length ≤105k, nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.