Class Solution
java.lang.Object
g1701_1800.s1760_minimum_limit_of_balls_in_a_bag.Solution
1760 - Minimum Limit of Balls in a Bag.<p>Medium</p>
<p>You are given an integer array <code>nums</code> where the <code>i<sup>th</sup></code> bag contains <code>nums[i]</code> balls. You are also given an integer <code>maxOperations</code>.</p>
<p>You can perform the following operation at most <code>maxOperations</code> times:</p>
<ul>
<li>Take any bag of balls and divide it into two new bags with a <strong>positive</strong> number of balls.
<ul>
<li>For example, a bag of <code>5</code> balls can become two new bags of <code>1</code> and <code>4</code> balls, or two new bags of <code>2</code> and <code>3</code> balls.</li>
</ul>
</li>
</ul>
<p>Your penalty is the <strong>maximum</strong> number of balls in a bag. You want to <strong>minimize</strong> your penalty after the operations.</p>
<p>Return <em>the minimum possible penalty after performing the operations</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [9], maxOperations = 2</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>Divide the bag with 9 balls into two bags of sizes 6 and 3. [<strong>9</strong> ] -> [6,3].</p>
</li>
<li>
<p>Divide the bag with 6 balls into two bags of sizes 3 and 3. [<strong>6</strong> ,3] -> [3,3,3]. The bag with the most number of balls has 3 balls, so your penalty is 3 and you should return 3.</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,4,8,2], maxOperations = 4</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>Divide the bag with 8 balls into two bags of sizes 4 and 4. [2,4, <strong>8</strong> ,2] -> [2,4,4,4,2].</p>
</li>
<li>
<p>Divide the bag with 4 balls into two bags of sizes 2 and 2. [2, <strong>4</strong> ,4,4,2] -> [2,2,2,4,4,2].</p>
</li>
<li>
<p>Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2, <strong>4</strong> ,4,2] -> [2,2,2,2,2,4,2].</p>
</li>
<li>
<p>Divide the bag with 4 balls into two bags of sizes 2 and 2. [2,2,2,2,2, <strong>4</strong> ,2] -> [2,2,2,2,2,2,2,2]. The bag with the most number of balls has 2 balls, so your penalty is 2 an you should return 2.</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [7,17], maxOperations = 2</p>
<p><strong>Output:</strong> 7</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= maxOperations, nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumSize
public int minimumSize(int[] nums, int maxOperations)
-