Menu

Post image 1
Post image 2
1 / 2
0

Optimizing Generosity: A Greedy Approach to LeetCode 455 (Assign Cookies)

DEV Community·Jerin·26 days ago
#cbMRn9Th
Reading 0:00
15s threshold

Difficulty : Easy Topics : Array, Two Pointers, Greedy, Sorting Platform : Leetcode Problem Statement 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 g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], 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. Problem Statement Simplified Give each children a cookies and each children have a dreed factor, give the result of how many children were satisfied. Mistakes and Learning Dont check for eact value - in greedy problems we should look for threhold not exact value.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More