Skip to main content
LeetCode 1760, Medium. Topics: Array, Binary Search. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 22 parametrized pytest cases, and a playground notebook:

Problem

You are given an integer array nums where the i<sup>th</sup> 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 of 1 and 4 balls, or two new bags of 2 and 3 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.

Examples

Constraints

  • 1 <= nums.length <= 10<sup>5</sup>
  • 1 <= maxOperations, nums[i] <= 10<sup>9</sup>

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026