Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kranthi0987
Created January 3, 2020 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kranthi0987/8f6742f80a3e8c71f6028b80b56c02b1 to your computer and use it in GitHub Desktop.
Save kranthi0987/8f6742f80a3e8c71f6028b80b56c02b1 to your computer and use it in GitHub Desktop.
Hackerrank Sock-market solution
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the sockMerchant function below.
def sockMerchant(n, ar):
count = 0
ar.sort()
ar.append('#')
i = 0
while i<n:
if ar[i]==ar[i+1]:
count = count+1
i+=2
else:
i+=1
return count
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment