Assign Cookies
Updated
Problem statement
You have some cookies to hand out to children. Each child gets at most one cookie, and each cookie goes to at most one child.
Child i has a greed factor g[i]: the smallest cookie size that makes that child content. Cookie j has size s[j]. If s[j] >= g[i], giving cookie j to child i makes the child content.
Return the largest number of children you can make content.
Function
findContentChildren(g: int[], s: int[]) → intExamples
Example 1
g = [4,2,1]s = [1,3]return = 2- The cookie of size
1makes the child with greed1happy. - The cookie of size
3makes the child with greed2happy. - No cookie has size
4or more, so the child with greed4stays unhappy. - The answer is
2.
Example 2
g = [1,3]s = [3,1]return = 2- If the child with greed
1takes the cookie of size3, the child with greed3is left with size1, which is too small. - Instead, give size
1to the child with greed1and size3to the child with greed3. - Both children are happy, so the answer is
2.
Example 3
g = [5,5]s = [1,2,3,4]return = 0- Both children need a cookie of size at least
5. - The largest cookie has size
4, so no child can be made happy. - The answer is
0.
Constraints
1 <= g.length <= 3 * 1040 <= s.length <= 3 * 1041 <= g[i], s[j] <= 231 - 1
More Amazon Phone Screen questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
- Find Maximum GreatnessTwilio · OATwilio interview questions
- Binge WatchingVanguard · OAVanguard interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions