Skip to content

Commit 88de7cc

Browse files
committed
Python file for finding number of pairs
1 parent 85ee276 commit 88de7cc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

maths/iterative_pair.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import math
2+
import os
3+
import random
4+
import re
5+
import sys
6+
from collections import Counter
7+
import doctest
8+
9+
#
10+
# Complete the 'sockMerchant' function below.
11+
#
12+
# The function is expected to return an INTEGER.
13+
# The function accepts following parameters:
14+
# 1. INTEGER n
15+
# 2. INTEGER_ARRAY ar
16+
#
17+
18+
19+
def sockMerchant(n, ar):
20+
"""
21+
>>> sockMerchant(9, [10, 20, 20, 10, 10, 30, 50, 10, 20])
22+
3
23+
>>> sockMerchant(4, [1, 1, 3, 3])
24+
2
25+
26+
"""
27+
28+
i = 0
29+
occur = Counter(ar)
30+
31+
for x in occur.values():
32+
i += x // 2
33+
return i
34+
35+
36+
if __name__ == "__main__":
37+
38+
n = int(input("Enter length of array:- \n").strip())
39+
40+
ar = list(map(int, input("Enter the elements: \n").rstrip().split()))
41+
42+
result = sockMerchant(n, ar)
43+
print(result)
44+
doctest.testmod()

0 commit comments

Comments
 (0)