Two assign cookies to children optimaly we should give for each child the closest higher cookie. By using this greedy approach overall sum of wasted cookies will be minimum amoung all. To use this greedy solution in effective way we can sort both arrays and use two pointers. We should move pointer of children only if there is enough cookies to make that child content. In each step we will try to make content child at position pointerG by searching the closes higher cookie value.

```
public class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int pointG = 0;
int pointS = 0;
while (pointG<g.length && pointS<s.length) {
if (g[pointG]<=s[pointS]) {
pointG++;
pointS++;
} else {
pointS++;
}
}
return pointG;
}
}
```