The Assign Cookies interview question is a greedy allocation problem. You have a list of children with specific greed factors and a list of cookies with specific sizes. A child will be content if they receive a cookie with a size greater than or equal to their greed factor. Your goal is to maximize the number of content children. This Assign Cookies coding problem is a perfect introduction to greedy optimization.
Companies like Apple and Amazon use this as a "warm-up" question. It tests if you can identify that a local optimal choice (giving the smallest possible sufficient cookie to the least greedy child) leads to a global optimal solution. It also checks your ability to use two-pointer logic on sorted data.
This follows the Array, Sorting, Two Pointers, Greedy interview pattern. By sorting both the children's greed factors and the cookie sizes, you can iterate through both lists once to make the best possible assignments.
Children's greed: [1, 2, 3], Cookies: [1, 1].
Greedy problems almost always require sorting the input. If you're trying to match two sets of values to satisfy a condition, sort them both and use the two-pointer approach to find the optimal pairings.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Bag of Tokens | Medium | Solve | |
| Boats to Save People | Medium | Solve | |
| Maximum Matching of Players With Trainers | Medium | Solve | |
| Minimize Maximum Pair Sum in Array | Medium | Solve | |
| Pancake Sorting | Medium | Solve |