Skip to content

Commit

Permalink
Added solution for Max Number of K-Sum Pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Jan 4, 2024
1 parent fdf61ae commit a3b3707
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions week5/max-number-of-k-sum-pairs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def maxOperations(self, nums: List[int], k: int) -> int:
ans=0
dic={}
for num in (nums):
if k-num in dic and dic[k-num] > 0:
ans+=1
dic[k-num]-=1
else:
dic[num]=dic.get(num,0)+1
return ans

0 comments on commit a3b3707

Please sign in to comment.