You're a parent with cookies to distribute. Each child has a greed factor; they're satisfied only if the cookie size is at least their greed factor.
Maximize the number of satisfied children.
With g = [1,2,3] (greed factors) and s = [1,1] (cookie sizes):
- Child with greed 1 can be satisfied by cookie of size 1.
- Child with greed 2 needs at least size 2. Only size 1 cookies left.
- Child with greed 3 can't be satisfied.
- child satisfied.
With g = [1,2] and s = [1,2,3]:
- Child 1 gets cookie 1. Child 2 gets cookie 2. (Or cookie 3.)
- children satisfied.
Constraints: g.length, s.length .