455. Assign Cookies
Easy
Problem:
Input: g = [1,2,3], s = [1,1]
Output: 1
Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3.
And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.
You need to output 1.What to learn:
>>> bisect.bisect_left([1,2,3,4,5], 3)
2
>>> bisect.bisect_right([1,2,3,4,5], 3)
3Solution:
Greedy algorithm
Binary search
Last updated