Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. You should give each child at most one cookie.

Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with. Each cookie j has a size s[j]. If s[j] >= g[i], you can assign cookie j to child i, and child i will be content.

Your goal is to maximize the number of content children and return the maximum number.

Note: This question is the same as 2410: Maximum Matching of Players With Trainers.

Example 1
Inputg = [1,2,3], s = [1,1]
Output1
Only the child with greed factor 1 can be content because both cookies have size 1.
Example 2
Inputg = [1,2], s = [1,2,3]
Output2
The cookies are large enough to make both children content, so the maximum number is 2.

Constraints

  • 1 <= g.length <= 3 * 10^4
  • 0 <= s.length <= 3 * 10^4
  • 1 <= g[i], s[j] <= 2^31 - 1

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate