Ctrl K

Spreading Stock Over Shops

Medium
A chain has shops shops. The warehouse holds several kinds of goods: stock[i] is the number of units of kind i. All of it must be delivered to the shops under these rules: - each shop receives goods of at most one kind, in any amount; - a shop may receive nothing. Let x be the largest number of units any single shop receives. Return the smallest possible x.
Example 1
shops=5, stock=[7, 4] → 3

Split the 7 units of the first kind across three shops (3, 2, 2) and the 4 units of the second across two (2, 2). The busiest shop holds 3.

Example 2
shops=3, stock=[1, 9, 2] → 9

Each kind needs at least one shop, so all 9 units of the second kind end up in a single shop.

Example 3
shops=4, stock=[10] → 3
Constraints
  • 1 ≤ len(stock) ≤ shops ≤ 10⁵
  • 1 ≤ stock[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStick Triples That Form a Triangle MediumBest-Paid Gig for Each Worker MediumA Plan for Draining Ponds MediumPrices That Fade With Each Sale MediumEven Out With Increments Medium
loading Python…
Input
shops=5, stock=[7, 4]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.