Skip to content
Decoder

Assign Cookies

Easy

Problem

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.

Example 1

Input
g = [1, 2, 3], s = [1, 1]
Output
1

Example 2

Input
g = [1, 2], s = [1, 2, 3]
Output
2

Example 3

Input
g = [5], s = []
Output
0

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.