Assign Cookies
Easy
LC #455
greedysortingtwo pointersNot attempted yet
Each child i is happy only with a cookie of size at
least g[i] (their greed). Cookie j has size
s[j]. Each child gets at most one cookie and each
cookie goes to at most one child.
Return the maximum number of happy children.
Example 1
Input: g = [1,2,3], s = [1,1]
Output: 1
Both cookies have size 1; only the child with greed 1 can be satisfied.
Example 2
Input: g = [1,2], s = [1,2,3]
Output: 2
Example 3
Input: g = [10,9,8,7], s = [5,6,7,8]
Output: 2
Cookies 7 and 8 satisfy the children with greed 7 and 8.
Constraints
- 1 <= g.length <= 3 * 10^4
- 0 <= s.length <= 3 * 10^4
- 1 <= g[i], s[j] <= 2^31 - 1