LeetCode 1760. Minimum Limit of Balls in a Bag
Binary Search
You are given an integer array nums
where the ith
bag contains nums[i]
balls. You are also given an integer maxOperations
.
You can perform the following operation at most maxOperations
times:
Take any bag of balls and divide it into two new bags with a positive number of balls.
For example, a bag of
5
balls can become two new bags of1
and4
balls, or two new bags of2
and3
balls.
Your penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.
Return the minimum possible penalty after performing the operations.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 10^5
1 <= maxOperations, nums[i] <= 10^9
Solution:
PreviousLeetCode 1755. Closest Subsequence SumNextLeetCode 1761. Minimum Degree of a Connected Trio in a Graph
Last updated