LeetCode 455 Assign Cookies - Implementation

The code

Sort both arrays. Two pointers to match.

def findContentChildren(g, s): g.sort() s.sort() child = cookie = 0

while child < len(g) and cookie < len(s):
    if s[cookie] >= g[child]:
        child += 1
    cookie += 1

return child

O(nlogn+mlogm)O(n \log n + m \log m) time, O(1)O(1) extra space.