imashutosh51

Assign Cookies

Feb 9th, 2026
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. '''
  2. sort both greed and cookies size, assign the smallest size cookie to a person which can satisfy the greed.
  3. '''
  4. class Solution:
  5.     def findContentChildren(self, g: List[int], s: List[int]) -> int:
  6.         g.sort()
  7.         s.sort()
  8.         ans=0
  9.         i,j=0,0
  10.         while j<len(s) and i<len(g):
  11.             if g[i]<=s[j]:
  12.                 i+=1
  13.                 j+=1
  14.                 ans+=1
  15.             else:
  16.                 j+=1
  17.         return ans
  18.        
Advertisement
Add Comment
Please, Sign In to add comment