Leetcode 2064. Minimized Maximum of Products Distributed to Any Store
[ OK ]microsoft-code-19 — full content available
[ INFO ]category: Coding difficulty: medium freq: Optional first seen: 2026-03-13
[MEDIUM][CODING][OPTIONAL]
$catproblem.md
Practice/Microsoft/Leetcode 2064. Minimized Maximum of Products Distributed to Any Store
Leetcode 2064. Minimized Maximum of Products Distributed to Any Store
CodingOptional
Problem
You are managing the distribution of products to retail stores. You have n retail outlets and several product types to distribute. Each product type has a specific quantity that needs to be allocated across the stores.
The rules are:
Each store can receive only one type of product (but can receive multiple units of that type)
You must distribute all units of every product type
You want to minimize the maximum number of items any single store receives
Your task is to determine the smallest possible value for the maximum number of items that any store will hold after optimal distribution.
Requirements
Implement a function that takes the number of stores n and an array quantities representing the quantity of each product type
Return the minimized maximum number of items any store will receive
All product units must be distributed
Each store receives only one product type (or remains empty)
Constraints
1 ≤ n ≤ 105
1 ≤ quantities.length ≤ 105
1 ≤ quantities[i] ≤ 105
The sum of all quantities can exceed n (requiring multiple stores per product type)
Examples
Example 1:
`
Input: n = 6, quantities = [11, 6]
Output: 3
Explanation: One optimal distribution:
Product type 0 (11 units): distribute as [3, 3, 3, 2] across 4 stores
Product type 1 (6 units): distribute as [3, 3] across 2 stores
Maximum items in any store = 3
`
Example 2:
`
Input: n = 7, quantities = [15]
Output: 3
Explanation: With 7 stores available for 15 items:
We can distribute as [3, 3, 3, 3, 3] using 5 stores
Maximum items in any store = 3
Using max=2 would require 8 stores (not enough)
`
Example 3:
Input: n = 1, quantities = [100000] Output: 100000 Explanation: Only one store available, must hold all 100000 items