Here is the greedy algorithm:
Sort children by greed (ascending)
Sort cookies by size (ascending)
Use two pointers: one for children, one for cookies
For each cookie: if it satisfies the current child, move both pointers; otherwise, move only the cookie pointer
Count satisfied children The two-pointer technique works because both arrays are sorted. You never need to go back. Time: . Space: . The two-pointer pattern appears in many greedy algorithms. It works when both arrays are sorted and you process each element exactly once.