Binary Search
Minimum Shipping Capacity (Find Smallest Divisor)
DESCRIPTION (inspired by Leetcode.com)
You're a logistics manager preparing to ship products from a warehouse. You have quantities of different product types that need to be packed into shipping boxes.
Each product type must be packed separately (different types can't share boxes). All boxes have the same capacity. If a product has more items than fit in one box, use multiple boxes.
Given an array of product quantities and a maximum number of boxes available, find the minimum box capacity needed to ship all products within the box limit.
Example 1:
Input:
quantities = [1, 2, 5, 9], maxBoxes = 6
Output: 5
Explanation: With box capacity 5, we need: ceil(1/5) + ceil(2/5) + ceil(5/5) + ceil(9/5) = 1 + 1 + 1 + 2 = 5 boxes total, which fits within the limit of 6.
Example 2:
Input:
quantities = [3, 6, 7, 11], maxBoxes = 8
Output: 4
Explanation: With capacity 4: ceil(3/4) + ceil(6/4) + ceil(7/4) + ceil(11/4) = 1 + 2 + 2 + 3 = 8 boxes, exactly meeting the limit.