MediumNo. 2064
Minimized Maximum of Products Distributed to Any Store — LeetCode 2064 Python Solution
- Pattern
- Monotonic Stack
- Topics
- Greedy, Array, Binary Search
- Reading time
- 2 min
- Source
- leetcode.com
The 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 ith product type.
Example
- Input
- n = 6, quantities = [11,6]
- Output
- 3
- Explanation
- One optimal way is:
Python solution
class Solution:
def minimizedMaximum(self, n: int, quantities: List[int]) -> int:
def check(x):
return sum((v + x - 1) // x for v in quantities) <= n
return 1 + bisect_left(range(1, 10**6), True, key=check)Complexity
- Time
- O(log n) or O(n log n)
- Space · auxiliary
- O(1)
Pattern: Monotonic Stack
Answer "what is the next greater element" for every position in one pass. LeetCode 2064. Minimized Maximum of Products Distributed to Any Store is filed here because the reference solution below belongs to the algorithm family this hub collects, even though its LeetCode tags point elsewhere.
The monotonic stack guide has the Python template for the pattern and the 225 LeetCode problems that use it.
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0410 | Split Array Largest Sum | Hard |
| 1648 | Sell Diminishing-Valued Colored Balls | Medium |
| 1671 | Minimum Number of Removals to Make Mountain Array | Hard |
| 2141 | Maximum Running Time of N Computers | Hard |
| 2333 | Minimum Sum of Squared Difference | Medium |
| 2358 | Maximum Number of Groups Entering a Competition | Medium |
Frequently asked questions
- How hard is LeetCode 2064. Minimized Maximum of Products Distributed to Any Store?
LeetCode 2064. Minimized Maximum of Products Distributed to Any Store is rated Medium on LeetCode.
- What topics does LeetCode 2064. Minimized Maximum of Products Distributed to Any Store cover?
LeetCode 2064. Minimized Maximum of Products Distributed to Any Store is tagged Greedy, Array and Binary Search on LeetCode.