Command Palette
Search for a command to run...
Problem 33.1 · Greedy AlgorithmsEasy
What it teaches: Exchange argument: give each child the smallest cookie that satisfies them.
Practise it on judges as “Assign Cookies”.
The problem
Child i is content with a cookie of size ≥ g[i]. Each child gets at most one cookie. Return the maximum number of content children.
Example 1
Input: g = [1, 2], s = [1, 2, 3]
Output: 2
Constraints
Pattern clues in the wording
- → Match items to requirements, maximise matches
These clues point to Greedy Choice: Make the best-looking choice at each step and never undo it, after proving that this choice is always safe.
Stuck? Take one hint at a time
Solution.java · starterimport java.util.*;
class Solution {
public int findContentChildren(int[] g, int[] s) {
return 0;
}
}
Write your solution locally or in your editor for now. The in-browser runner (Java first, then Python, C++ and more) will run these tests right here.
Test cases
| # | Input | Expected |
|---|
| 1 | g = [1,2,3] s = [1,1] | 1 |
| 2 | g = [1,2] s = [1,2,3] | 2 |