BackmediumUncategorized uncategorized medium

Optimal Storage Allocation Solution

Problem Statement

Given an array of integers `capacities` representing the storage capacities of a set of containers and an integer `totalSupplies` representing the total amount of supplies to be stored, find the maximum number of supplies that can be stored without exceeding the capacities of the containers.

Example 1
Input
{"capacities":[10,20,30],"totalSupplies":50}
Output
50

Explanation: The maximum number of supplies that can be stored is 50 by filling the first two containers: 10 + 20 + 20 = 50.

Constraints

  • 1 <= capacities.length <= 10^5
  • 1 <= capacities[i] <= 10^9
  • 1 <= totalSupplies <= 10^12
  • capacities and totalSupplies are non-negative integers
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free