Skip to content

Commit f9b1daa

Browse files
authored
Create 2554-maximum-number-of-integers-to-choose-from-a-range-I.py
hashmap solution
1 parent f8c3978 commit f9b1daa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxCount(self, banned: List[int], n: int, maxSum: int) -> int:
3+
nums = {x:1 for x in range(1,n+1)} # hashmap for storing the required elements
4+
for i in banned:
5+
if nums.get(i):
6+
del nums[i]
7+
sum = 0
8+
count = 0
9+
for i in nums:
10+
sum += i
11+
if sum <= maxSum:
12+
count += 1
13+
else:
14+
break
15+
return count

0 commit comments

Comments
 (0)