Minimized Maximum of Products Distributed to Any Store

Medium Topics Company Tags

Distribute every product among n stores. The entry quantities[i] is the number of products of type i. A store may receive products of at most one type, while a type may be split among several stores. Stores may remain empty. Return the smallest possible maximum number of products assigned to any single store.

Example 1:

Input: n = 4
quantities = [8,4]

Output: 4

Explanation: Split the eight products of the first type into stores holding 4 and 4, and split the four products of the second type into stores holding 2 and 2. A limit of 3 would need three stores for the first type and two for the second, exceeding four stores. The answer is 4.

Example 2:

Input: n = 2
quantities = [3,7]

Output: 7

Explanation: There are two types and two stores, so each type must go to its own store. Their loads are 3 and 7, giving a minimum maximum of 7.

Example 3:

Input: n = 5
quantities = [2,1]

Output: 1

Explanation: Use three stores, each holding one product, and leave two stores empty. All products are placed and the largest load is 1.

Constraints:

  • 1 <= quantities.length <= n <= 100000
  • 1 <= quantities[i] <= 100000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.