The edge cases threw me for a fit on this problem! I didn't think about using a seen set - that was cool! I just updated the hashmap in place. Thanks Tim! counts = Counter(nums) pairs = 0 for num in nums: #find the complement complement = k - num if complement in counts: #edge case 1, enough elements if counts[num] > 0 and counts[complement] > 0: #edge case when they are the same and count at nums < 2 if num == complement and counts[num] < 2: #we need two of the same continue pairs += 1 counts[num] -= 1 counts[complement] -= 1 return pairs
great video, i was also confused by the description. "remove them from the array" followed by "Return the maximum number of operations you can perform on the array." seems they only wanted to latter, and i solved this with a two pointer. thank you for the help!
The edge cases threw me for a fit on this problem! I didn't think about using a seen set - that was cool! I just updated the hashmap in place. Thanks Tim!
counts = Counter(nums)
pairs = 0
for num in nums:
#find the complement
complement = k - num
if complement in counts:
#edge case 1, enough elements
if counts[num] > 0 and counts[complement] > 0:
#edge case when they are the same and count at nums < 2
if num == complement and counts[num] < 2: #we need two of the same
continue
pairs += 1
counts[num] -= 1
counts[complement] -= 1
return pairs
Nice work Jan! It's really cool to see different efficient approaches
great video, i was also confused by the description. "remove them from the array" followed by "Return the maximum number of operations you can perform on the array." seems they only wanted to latter, and i solved this with a two pointer. thank you for the help!
Great video man!
can you please write in the description of your videos the time and space complexity it would really help!
Hi, thanks a lot for your videos. You make problems look very simple. Could you please do videos for Leetcode weekly contest questions ?
Thanks for watching! II'll try someday but some of those hard questions are really really hard for me
Good video bro, next time tho maybe slow down a little bit. 😀
Super Great!!!