Loading...
You are given two integer arrays. demands[i] is the smallest size that will satisfy demand i, and supplies[j] is the size of supply j.
Supply j satisfies demand i when supplies[j] >= demands[i]. Each supply may be assigned to at most one demand, and each demand may receive at most one supply.
Return the largest number of demands that can be satisfied at once.
Note that supplies may be empty, in which case no demand can be satisfied.
Input: demands = [1,2,3], supplies = [1,1]
Output: 1
Explanation: Both supplies have size 1, so each can satisfy only the demand of size 1. Only one of them can be assigned to it, and the demands of size 2 and 3 cannot be satisfied at all.
Input: demands = [1,2], supplies = [1,2,3]
Output: 2
Explanation: The supply of size 1 satisfies the demand of size 1, and either remaining supply satisfies the demand of size 2, so both demands are satisfied.
demands.length ≤3⋅104supplies.length ≤3⋅104demands[i], supplies[j] ≤231−1Click "Run" to test with sample cases or "Submit" to run all tests.