We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 63c7184 commit 97d98d8Copy full SHA for 97d98d8
455-Assign Cookies/solution.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def findContentChildren(self, g: List[int], s: List[int]) -> int:
3
+
4
+ # 1. Sort both the array g and s in ascending order
5
+ g.sort() # O(n log n)
6
+ s.sort() # O(m log m)
7
8
+ # 2. Initialize the pointer j(cookies) to 0
9
+ j = 0
10
11
+ # 3. Loop through each child's greed factor in g
12
+ for _,__ in enumerate(g): # O(n+m)
13
+ # 4. Move through the cookie sizes until we find some
14
+ while j < len(s) and s[j] < __:
15
+ j += 1
16
+ # 5. if there are no more cookies left, return the number of children so far
17
+ if j >= len(s):
18
+ return _
19
+ # 6. Move to the next cookie
20
21
22
+ return len(g)
23
24
25
26
0 commit comments