Assign Cookies

Try to solve the Assign Cookies problem.

Statement

You are given two integer arrays:

  1. greed_factors: This array represents the minimum cookie size required for each child to be content. Specifically, greed_factors[i] denotes the minimum cookie size that child i will accept to be satisfied.

  2. cookie_sizes: This array represents the sizes of the available cookies. For example, cookie_sizes[j] denotes the size of cookie j.

Your objective is to distribute the cookies in a way that maximizes the number of content children. A child i is content if they receive a cookie that is at least as large as their greed factor, i.e., cookie_sizes[j] >= greed_factors[i]. Each child can be assigned at most one cookie, which can only be given to one child.

Write an algorithm to maximize the number of children who can be content by assigning available cookies appropriately.

Constraints:

  • 11 \leq greed_factors.length 1000\leq 1000

  • 00 \leq cookie_sizes.length 1000\leq 1000

  • 11 \leq greed_factors[i], cookie_sizes[j] 105\leq 10^5

Examples

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.