DEV Community

Discussion on: How to Solve Sock Merchant Code Challenge

Collapse
shivamseth05 profile image
Shivam Seth • Edited on

Complete the sockMerchant function below: ( Solution In Python)

def sockMerchant(n, ar):
pears = 0
color = set()
for i in range(len(ar)):
if ar[i] not in color:
color.add(ar[i])
else:
pears += 1
color.remove(ar[i])
return pears
if name == 'main':

n = int(input())

ar = list(map(int, input().rstrip().split()))
ar.sort()


result = sockMerchant(n, ar)
print(result)
Enter fullscreen mode Exit fullscreen mode