dsa · easy

Assign Cookies

greed[i] is how large a cookie child i needs to be content. sizes[j] is the size of cookie j. A child may receive at most one cookie, and cookie j can satisfy child i only when sizes[j] >= greed[i]. Cookies that nobody gets are fine. Return the maximum number of content children.

Example

greed = [2, 4], sizes = [1, 2, 3].

The size-1 cookie is too small for anyone. Give size 2 to the child who needs 2. The leftover size 3 still cannot satisfy the child who needs 4. One content child → 1.

greed = [1, 2], sizes = [1, 2, 3]: both children can be given a cookie that meets them → 2.

greed = [5], sizes = []: no cookies at all → 0.

## Arguments - greed — minimum cookie size that satisfies each child - sizes — cookie sizes (may be empty)

Constraints

1 <= greed.length <= 4*10^4 0 <= sizes.length <= 4*10^4 1 <= greed[i], sizes[j] <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,4]
[1,2,3]

Expected:
1

Example 2

Input:
[1,2]
[1,2,3]

Expected:
2

Example 3

Input:
[5]
[]

Expected:
0

Open in the Dojo editor