Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Minimized Maximum of Products Distributed to Any Store

Medium

Topics
ArrayBinary Search

You have n product types. The ith type has nums[i] units in stock. You want to distribute all units across target specialty stores with these rules:

  • Each store carries at most one product type (but as many units of that type as you assign).
  • Some stores may remain empty.

Minimize the maximum number of units assigned to any single store. Return that minimized maximum.

Example 1

Input:  nums = [11,6], target = 10
Output: 2
Explanation: Assign product 0 (11 units) across 6 stores: ceil(11/2)=6 stores each getting at most 2. Assign product 1 (6 units) across 3 stores: ceil(6/2)=3 stores each getting at most 2. Uses 9 stores total (<=10). The max any store gets is 2.

Example 2

Input:  nums = [15,10,10], target = 7
Output: 5
Explanation: With max=5: product 0 needs ceil(15/5)=3, product 1 needs ceil(10/5)=2, product 2 needs ceil(10/5)=2. Total=7 stores. With max=4: 4+3+3=10>7. So 5 is the answer.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^5
  • nums.length <= target <= 10^5
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access