Max Number of K Sum Pairs (Leetcode 1679)
Problem Link: https://leetcode.com/problems/max-number-of-k-sum-pairs/
class Solution:
def maxOperations(self, nums: List[int], k: int) -> int:
d={}
count=0
for i in nums:
if(k-i in d):
count=count+1
if(d[k-i]==1):
del d[k-i]
else:
d[k-i]=d[k-i]-1
else:
if(i not in d):
d[i]=1
else:
d[i]+=1
return count
Last updated