easyGreedyPure DSA~14 min
Allocate Compute Credits
Each tenant needs a minimum compute-credit grant to run. You hold grants of various sizes. Maximise how many tenants you can satisfy, one grant per tenant.
Problem
Given an array need where need[i] is tenant i's minimum requirement, and an array grants of available grant sizes, assign at most one grant per tenant (a grant satisfies a tenant if grant ≥ need). Return the maximum number of satisfied tenants.
Input
Arrays need (0 ≤ len ≤ 3·10^4) and grants (0 ≤ len ≤ 3·10^4), positive sizes.
Output
An integer — the maximum number of satisfied tenants.
Constraints
- Each grant and each tenant is used at most once
- A grant satisfies a tenant when grant ≥ need
- Sizes are positive integers
Examples
Example 1
Input
need = [1,2,3], grants = [1,1]
Output
1
Only the tenant needing 1 can be satisfied.
Example 2
Input
need = [1,2], grants = [1,2,3]
Output
2
Grant 1 → tenant 1, grant 2 → tenant 2.