sockMerchant HackerRank Solution: Looking for sockMerchant solution for Hackerrank problem? Get solution with source code and detailed explainer video.

There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.
Example:
n=7
arr=[1,2,1,2,1,3,2]Go to problem statement

## Explanation Video:

Mentor: Satyendra Jaiswal
Langauge: Python

## Source Code:  for `sockMerchant` function

``````
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
s=0
for val in Counter(ar).values():
s+=val//2
return s

``````
coming soon…
coming soon…

## Full Source Code:`sockMerchant `

``````
#!/bin/python3

import math
import os
import random
import re
import sys
from collections import Counter

# Complete the sockMerchant function below.
def sockMerchant(n, ar):
s=0
for val in Counter(ar).values():
s+=val//2
return s

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

n = int(input())

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

result = sockMerchant(n, ar)

fptr.write(str(result) + '\n')

fptr.close()

``````
coming soon…
coming soon…