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.
g = [1,2,3], s = [1,1]1g = [1,2], s = [1,2,3]2Constraints
- 1 <= g.length <= 3 * 10^4
- 0 <= s.length <= 3 * 10^4
- 1 <= g[i], s[j] <= 2^31 - 1
Asked at 9 companies
Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.