Greedy Algorithms8 sections · 316 units
Open in Course

Problem - Assign Cookies

Entry-level greedy

You have children with greed factors and cookies with sizes. A child ii is content if they get a cookie of size at least greed[i]greed[i]. Each cookie can go to at most one child. Maximize the number of content children.

Example: children greed = [1, 2, 3], cookies = [1, 1]. Answer: 11. Only the child with greed 11 can be satisfied. Here's your entry problem for greedy. Before reading the solution, try to answer: what should you sort by? Which child should get which cookie?