15% off all plans & roadmaps Use code
See plansLeetCode 2064 · Solution & editorial
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.
Minimized Maximum of Products Distributed to Any Store is a Binary Search Patterns problem, in the On Answer / Condition Function subpattern. The pattern covers standard binary search, rotated arrays, first/last occurrence, and search on answer space
Learn binary search on answer space for optimization problems like Koko eating bananas and capacity to ship packages.
The reference solution runs in O(nlogm) time and O(1) space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Minimized Maximum of Products Distributed to Any Store is a Binary Search Patterns problem, in the On Answer / Condition Function subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.