- Denisse's Newsletter
- Posts
- Day 5 Solution + Jobs!
Day 5 Solution + Jobs!

Hello and welcome back brave human being,
Before we delve into the problem, let me share some pieces of wisdom. The important thing is not what one is born with but what use one makes of the equipment.
It means that if you are doing these problems, a problem a day, you are one step closer to your goal. You are putting in the work 💪 .
Day 5: 455. Assign Cookies
Efficiently distribute cookies among children (with greed factors represented by array g and cookie sizes by array s) to maximize contentment.
This problem is also a good introduction to greedy paradigm.
For this problem, we learned that we can also use two-pointers to iterate two arrays, they only need to be …. sorted!
The first step is to sort both arrays. Once sorted we can initialize both pointers at the beginning of each array. Now, to move the kid’s pointer we must satisfy the condition:
Otherwise, we can’t feed the cookie to the kid and we must continue to find a cookie that satisfies the condition so also check:
else if (g[kidsPointer]>s[cookiesPointer]){
cookiesPointer++;
}
And if you think about it, the kid’s Pointer has the result as well, no need to keep an extra counter.
Here is an example…

Final Solution

Let’s pause to go over the time complexity…
Sorting the kid’s array would cost us: O(N Log N)
Sorting the cookie’s array would cost us: (M Log M)
Kid’s pointers: N
Cookies pointers: M
However, in big O notation, we often disregard constants and lower-order terms. So, we can simplify this to:
Time Complexity: O(max(NlogN,MlogM))
Need motivation to be consistent?
Add this problem to your log and when the challenge is done send it to me! You’ll be in for a treat.
JOBS @AUBA!
🌟 Join Auba's Team: Revolutionizing the Global Supply Chain
We're on a mission at Auba to transform supply chain management and we need innovative minds like yours! Our AI-driven solutions are reshaping global logistics, tackling disruptions to save billions.
Why Join Auba?
* Unlimited Holidays: We prioritize your well-being with flexible holiday time.
* Flexible, Remote Working: Work when and where you're most productive.
* Gold-Plated Healthcare: Premium healthcare for you and your family.
* Meaningful Equity: Share in our success as you contribute to it.
* Top-of-the-Line Equipment: We provide the best tools for you to excel.
* A Supportive Team: Join a group of passionate, collaborative professionals.
Be part of a team that's not just solving challenges but turning them into groundbreaking opportunities.
🚀 Ready to revolutionize the supply chain with us? Apply now and take your career to new heights at Auba!
Link To Apply ➡️: https://auba.pinpointhq.com/en
Reply