Credit Grant Match
A promotions service hands out credit grants of various sizes to users who each need a minimum credit to be satisfied. A user is satisfied if assigned a grant at least as large as their need. Maximise the number of satisfied users.
Problem
Given an array need where need[i] is user i's minimum credit, and an array grant of available grant sizes, assign at most one grant per user (each grant used once) to maximise the count of satisfied users. Return that maximum count.
Input
Arrays need (length u) and grant (length g), 0 ≤ u, g ≤ 10^5, positive values.
Output
A single integer — the maximum number of satisfied users.
Constraints
- Each grant is used at most once
- A user needs a grant ≥ their need value
- 0 ≤ u, g ≤ 100,000
Examples
Example 1
Input
need = [1, 2, 3], grant = [1, 1]
Output
1
Both grants are size 1; only the user needing 1 can be satisfied.
Example 2
Input
need = [1, 2], grant = [1, 2, 3]
Output
2
Grant 1 satisfies need 1 and grant 2 satisfies need 2.