554. Minimum Limit of Balls in a Bag

HardBinary SearchBinary Search on AnswerArray

You have bags of balls; in one operation you may split a bag into two bags with positive counts. After at most maxOperations operations, the penalty is the maximum number of balls in any bag. Return the minimum possible penalty. Input: '[nums], maxOperations'.

Input: '[nums], maxOperations'.

Output: Integer — the minimum possible penalty.

Examples

Example 1
Input: [9], 2
Output: 3
Explanation: Split 9 into 3,3,3 using 2 operations.
Example 2
Input: [2,4,8,2], 4
Output: 2
Explanation: Reduce the maximum bag to 2.
Example 3
Input: [1], 1
Output: 1
Explanation: Already minimal.

Constraints

Asked by

FlipkartBloombergAmazonGoogleMetaMicrosoft
Solve this problem in the editor →