LeetCode 2064, Medium. Topics: Array, Binary Search, Greedy. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 39 parametrized pytest cases, and a playground notebook:
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<sup>th</sup> 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 x represent the maximum number of products given to any store. You want x to 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.
Examples
Constraints
- m == quantities.length
- 1 <= m <= n <= 10^5
- 1 <= quantities[i] <= 10^5
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026