Skip to content

Commit dec57c5

Browse files
authored
Create number-of-students-unable-to-eat-lunch.py
1 parent 6e0db38 commit dec57c5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def countStudents(self, students, sandwiches):
9+
"""
10+
:type students: List[int]
11+
:type sandwiches: List[int]
12+
:rtype: int
13+
"""
14+
count = collections.Counter(students)
15+
for i, s in enumerate(sandwiches):
16+
if not count[s]:
17+
break
18+
count[s] -= 1
19+
else:
20+
i = len(sandwiches)
21+
return len(sandwiches)-i

0 commit comments

Comments
 (0)