Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.

Note:

You may assume the greed factor is always positive.

You cannot assign more than one cookie to one child.

#### java

https://discuss.leetcode.com/topic/67676/simple-greedy-java-solution

Simple Greedy Java Solution

Just assign the cookies starting from the child with less greediness to maximize the number of happy children .

https://discuss.leetcode.com/topic/68455/array-sort-two-pointer-greedy-solution-o-nlogn

Array sort + Two pointer greedy solution O(nlogn)

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.

https://discuss.leetcode.com/topic/68288/java-solution-with-binary-search-tree

Java Solution with binary search tree

#### cpp

https://discuss.leetcode.com/topic/68858/c-short-solution

C++ short solution

#### python

https://discuss.leetcode.com/topic/67591/python-concise-efficient-solution

Python concise & efficient solution

My solution from the contest:

O(nlogn) time and O(1) space