Assign Cookies

preview_player
Показать описание
----------------------------------------------------------------------------------------------------------------

This is a commonly asked interview question according to LeetCode (2020)! assign cookies coding solution. If you give me 5 minutes you'll thank me if this appears during your interview! Coding Interviews assign cookies (LeetCode) question and explanation.

DISCORD CHANNEL
----------------------------------------------------------------------------------------------------------------
1. Ask me questions directly (as well as other members)
2. Ask about and discuss previous interview experiences
3. Find mock interview partners
4. Share helpful videos for interview preparation, and more!

This question is commonly asked by the following companies: ???

Intuition behind solution: sort both your arrays. Have one pointer to point at the largest cookie and one pointer to point at the greediest child. While both pointers are greater than or equal to 0, try to assign cookies. If you can give the ith cookie to the jth child, decrement both pointers and increment your return variable, content children. If you can't, i.e. the cookie is too small for the greedy child, try assigning that cookie to the next greedy child (which means decrement j). Once your loop breaks return your number of content children.

MUSIC
----------------------------------------------------------------------------------------------------------------
[this is america] by piep*

Рекомендации по теме
Комментарии
Автор

Good to see that you started uploaded your videos again consistently

anirudhatalmale
Автор

I really enjoy your explanation and all the time I am studying the algorithms you are solving

nosoyyotampoco
Автор

As a parent, the greediest children get the cookies is so morally wrong.... Satisfy the least greediest child first! And you won’t even need to deal with valuable contentChildren as i++!

Linyuchenandrew
Автор

Man you got such a nice approach towards identifying Dynamic Programming and recursive questions ! Can you make a video about how you solve DP programs or write recursive programs ? I can't seem to get a hang of it and it would help a lot if you can make a video for it :) Thanks keep posting :)

sabio
Автор

Can you please sort your questions by data structure (playlist).

palak
Автор

Hi Kevin, first of all awesome channel and great content you have got here. I am a huge fan and have been following you since some days. one request, can you pls upload videos of 100 most liked questions on leetcode.

rak
Автор

I was thinking of doing the opposite. In other words, order the arrays in ascending order instead of descending order to give more cookies to the less greedier ones. Can you please tell me if there is anything wrong with this approach?

mithunaditya
Автор

Should it not be || instead of &&?

YouTube_Staff
Автор

Could you also use 2 max heaps to solve this?

tilom
Автор

Your speed is good, but the memory efficiency is only less than 9.52% of other online Java submissions. When we do these, should we aim for 100/100, or should we just try to get as many accepted solutions as possible regardless of runtime/memory just to learn the patterns in the questions? Great vid btw

JackWutang
Автор

Is there a way to sort an array of millions of binary strings each of length 10 characters in o(n) time

lalithalalli
Автор

I am scratching my head if this can be optimized without Sorting.

DharmicYoddha