Skip to content

Commit 97d98d8

Browse files
authored
Added problem 455
1 parent 63c7184 commit 97d98d8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

455-Assign Cookies/solution.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
j += 1
21+
22+
return len(g)
23+
24+
25+
26+

0 commit comments

Comments
 (0)