Minimized Maximum of Products Distributed to Any Store - Problem
You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the i-th product type.
You need to distribute all products to the retail stores following these rules:
- A store can only be given at most one product type but can be given any amount of it.
- After distribution, each store will have been given some number of products (possibly 0). Let
xrepresent the maximum number of products given to any store. You wantxto be as small as possible, i.e., you want to minimize the maximum number of products that are given to any store.
Return the minimum possible x.
Input & Output
Example 1 — Basic Case
$
Input:
n = 6, quantities = [11,6]
›
Output:
3
💡 Note:
With max 3 per store: Product type 0 needs ceil(11/3) = 4 stores, product type 1 needs ceil(6/3) = 2 stores. Total: 4 + 2 = 6 stores ≤ 6.
Example 2 — Single Product Type
$
Input:
n = 7, quantities = [15]
›
Output:
3
💡 Note:
Only one product type with 15 units. With max 3 per store: ceil(15/3) = 5 stores ≤ 7. With max 2: ceil(15/2) = 8 stores > 7. So minimum possible maximum is 3.
Example 3 — Multiple Small Quantities
$
Input:
n = 1, quantities = [100000]
›
Output:
100000
💡 Note:
Only 1 store available, so it must take all 100000 products of the single type.
Constraints
- m == quantities.length
- 1 ≤ m ≤ n ≤ 105
- 1 ≤ quantities[i] ≤ 105
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code