Skip to content

2064. Minimized Maximum of Products Distributed to Any Store #830

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We can use a binary search on the maximum possible number of products assigned to any store (x). Here’s a step-by-step explanation and the PHP solution:

Approach

  1. Binary Search Setup:

    • Set the lower bound (left) as 1 (since each store can get at least 1 product).
    • Set the upper bound (right) as the maximum quantity in quantities array (in the worst case, one store gets all products of a type).
    • Our goal is to minimize the value of x (maximum products given to any store).
  2. Binary Search Logic:

    • For each mid-point x, check if it’s feasible to distribute all products such that no store has more than x products.
    • Use a helper function canDistribute(x) to determine feasibility.
  3. Feasibility …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 14, 2024
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants