> For the complete documentation index, see [llms.txt](https://emmaguo100.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emmaguo100.gitbook.io/leetcode/02-18-2022-455.md).

# 02/18/2022 455

Method:

* Greedy and 2 pointers
* Sort both the arrays and maintain pointers at each array
* Move cookie pointer until greed at current pointer is less than or equal to cookie-size at current pointer.
* Move greed pointer and cookie pointer when the condition is satisfied and increment count, otherwise only move cookie pointer.&#x20;

> **T/S:** O(m lg m + n lg n)/O(m + n), where m = size(greed), n = size(cookieSize)

class Solution { public int findContentChildren(int\[] g, int\[] s) { if(g == null || g.length == 0 || s == null || s.length == 0) return 0;

```
    Arrays.sort(g);
    Arrays.sort(s);
    
    int i = 0, j = 0, count = 0;
    int childrenSize = g.length;
    int cookieSize = s.length;
    
    while(i < childrenSize && j < cookieSize){
        if(g[i] <= s[j]){
            i++;
            count++;
        }
        j++;
    }
    return count;
    
}
```

}
