Solution 1 - Greedy (Two Pointers)
Sort greed factors and cookies; assign the smallest cookie that satisfies the next child.
Sort greed factors and cookies; assign the smallest cookie that satisfies the next child.
""" 0455.1 - Assign Cookies - Solution 1 - Greedy (Two Pointers) """
from typing import List
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
i = j = 0
while i < len(g) and j < len(s):
if s[j] >= g[i]:
i += 1
j += 1
return i
if __name__ == "__main__":
print(Solution().findContentChildren([1,2,3],[1,1])) # 1