Sock Merchant -HACKERRANK

Problem statement:
John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.
Explanation:
Given that n=7
which says array size is 7
and Array is [1,2,1,2,1,3,2]
here number of ones=3
number of twos=3
number of threes=1
so number of pairs=2
one sock pair with number 1
one sock pair with number 2
SO there are 2 pairs.
HOW TO SOLVE:
Use a array which stores count of array elements .number of pairs is equal to sum of each count value divided by 2
This is a simple approach.
IMPLEMENTATION:
#include
int main()
{
int n,i,k=0,array[100],count[100]={0},pairs=0;
scanf("%d",&n);//read size of array
for(i=n-1;i>=0;i--)
scanf("%d",&array[i]);//read elements into array
for(i=n-1;i>=0;i--)
count[array[i]]++;//maintain count for each element
for(i=n-1;i>=0;i--)
pairs+=(count[array[i]]/2);
printf("%d",pairs);//print pair count
return 0;
}
Python uses built in methods to find count hence we can find answer with less code
n=int(input())
arr=list(map(int,input().split())
s=list(set(arr)) # we find count for each element only once, as set removes duplicates
pairs=0 #initialize pairs to zero
for i in range(len(s)):
pairs+=arr.count(i)//2
print(pairs)
HOPE THIS HELPS ...............
HAPPY CODING..........