Imagine you're a distribution manager for a retail chain! You have n specialty stores and m different product types with varying quantities that need to be distributed efficiently.
You're given an integer n representing the number of specialty retail stores, and an array quantities where quantities[i] represents the number of products of the i-th product type.
Distribution Rules:
- Each store can receive at most one product type (but any amount of that type)
- All products must be distributed
- Some stores may receive no products at all
Goal: Minimize the maximum number of products any single store receives. If x represents the maximum products given to any store, find the smallest possible value of x.
Example: With 6 stores and quantities [11, 6], you could give 11 products of type 1 to store 1, and 6 products of type 2 to store 2. But you could also split: give 6 products of type 1 to store 1, 5 to store 2, and 6 of type 2 to store 3. The maximum would be 6 instead of 11!
Input & Output
Visualization
Time & Space Complexity
We try each possible maximum value and for each one, we check all m product types
Only using a few variables for calculation
Constraints
- m == quantities.length
- 1 โค m โค n โค 105
- 1 โค quantities[i] โค 105
- Key insight: We always have enough stores (n โฅ m)