← back to unit
Challenge
# sorting advanced
Cookie Fairness
Each kid has an appetite; each cookie has a size. A kid is happy with any cookie at least as big as their appetite — and each cookie feeds one kid. 🍪
You get appetites and cookies. Hand out cookies as cleverly as possible and print the most kids you can make happy.
Example:
Input: appetites = [1, 2, 3], cookies = [1, 1]
Output: 1
Sorting both, the smallest appetite (1) gets the first cookie (size 1) and is happy. The next cookie (size 1) is too small for appetite 2, so only 1 kid ends up happy.
💡 need a hint?
sort-cookie-fairness.py🔒 given lines are locked — write your code in between
loading...