Skip to content

Commit

Permalink
Merge pull request #227 from Varalakshmi2354/newpotd
Browse files Browse the repository at this point in the history
POTD_30_OCT_2024_pairs with diff k
  • Loading branch information
Gyanthakur authored Oct 31, 2024
2 parents 79e8521 + 5217b02 commit f1ff360
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions october_2024/GFG_POTD_30_OCT_2024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from collections import Counter

class Solution:
def countPairsWithDiffK(self, arr, k):
num_count = Counter(arr) # Count occurrences of each element
count = 0

for num in num_count:
# Check for pairs (num, num + k)
if num + k in num_count:
count += num_count[num] * num_count[num + k]

return count

0 comments on commit f1ff360

Please sign in to comment.