Skip to content

Commit 881b4ed

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3c6068e commit 881b4ed

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

data_structures/arrays/pairs_with_given_sum.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
88
"""
99

10+
1011
def pairs_with_sum(arr: list[int], req_sum: int) -> int:
1112
"""
1213
Return the number of pairs with sum equal to req_sum.
13-
14+
1415
>>> pairs_with_sum([1, 5, 7, 1], 6)
1516
2
1617
>>> pairs_with_sum([1, 1, 1, 1, 1, 1, 1, 1], 2)
@@ -20,20 +21,21 @@ def pairs_with_sum(arr: list[int], req_sum: int) -> int:
2021
"""
2122
count = 0
2223
seen = {}
23-
24+
2425
for num in arr:
2526
complement = req_sum - num
2627
if complement in seen:
2728
count += seen[complement]
28-
29+
2930
if num in seen:
3031
seen[num] += 1
3132
else:
3233
seen[num] = 1
33-
34+
3435
return count
3536

37+
3638
if __name__ == "__main__":
3739
from doctest import testmod
38-
testmod()
3940

41+
testmod()

0 commit comments

Comments
 (0)