Assign Cookies
A teacher has students with minimum acceptable cookie sizes in Student, and available cookie sizes in Cookie. A cookie can satisfy a student when its size is…
A teacher has students with minimum acceptable cookie sizes in `Student`, and available cookie sizes in `Cookie`. A cookie can satisfy a student when its size is at least that student's demand. Each student receives at most one cookie, and each cookie is used at most once. Return the maximum number of satisfied students. Cookies may be left unused; the cookie array may be empty.
- 1 <= Student.length <= 30000 - 0 <= Cookie.length <= 30000 - 1 <= Student[i], Cookie[j] <= 2147483647 - The bounded teaching trace accepts at most 8 students and 8 cookies, with values at most 1000000000; coding retains the complete bounds above.
Example 1: input Student = [1,2,3], Cookie = [1,1]; output 1. Only one size-1 demand can be served.
Example 2: input Student = [1,2], Cookie = [1,2,3]; output 2. Assign size 1 to demand 1 and size 2 to demand 2; leave size 3 unused.
Example 3: input Student = [1], Cookie = []; output 0. No cookie is available.
Category: Greedy Algorithms. Topic: greedy. Difficulty: Easy. Patterns: greedy, sorting.