Skip to content

Assign Cookies

EasyGreedy
Decode it first. Clues, constraints, pattern and plan before any code.

Child i is happy with any cookie of size at least g[i]. 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.

g = [1, 2, 3], s = [1, 1]     →  1
g = [1, 2],    s = [1, 2, 3]  →  2
g = [5],       s = []         →  0

Constraints

  • 1 <= g.length <= 3 * 10^4
  • 0 <= s.length <= 3 * 10^4
  • 1 <= g[i], s[j] <= 2^31 - 1