Menu
CoddyTech

Assign Cookies

Each child i has a greed factor g[i]: the smallest cookie size that makes them happy. Each cookie j has a size s[j]. A child is content when they get one cookie whose size is at least their greed factor. Every child gets at most one cookie and every cookie goes to at most one child. Return the largest number of children you can make content.

Function

findContentChildren(g: integer-array, s: integer-array) → integer
ginteger-array
the greed factor of each child, the smallest cookie size they accept
sinteger-array
the size of each cookie
Returnsinteger
the most children that can each get a cookie at least as big as their greed factor

Constraints

  • 1 ≤ g.length, s.length ≤ 5000
  • 1 ≤ g[i], s[j] ≤ 105
  • The two arrays may have different lengths, and neither is sorted.

Examples

Input
g = [4, 2, 7]s = [3, 5, 1, 2]
Output
2
Explanation
Sorted, the children want 2, 4 and 7. Cookie 2 feeds the child who wants 2 and cookie 5 the child who wants 4. No cookie reaches 7, so the answer is 2.
challenge icon

Follow-up

What if each child also has a largest cookie they will accept, so a cookie fits only inside a range? Which waiting child should each cookie go to then?

Reset code
def findContentChildren(g, s):
    # Write code here

Test #1

Test #2

Arguments

g = [4, 2, 7]
s = [3, 5, 1, 2]

Expected Output

2